Openerp how to change bar chart single column multi colour into multiple column?

1k Views Asked by At

The below bar chart code:-

var data = [
    {data: [[0, 5],[1,2],[2,4],[3,1]], label:'t1'},
    {data: [[0,2],[1, 5],[2,2],[3,3]], label:'t2'},
    {data: [[0,3],[1, 7],[2,5],[3,2]], label:'t3'},
    {data: [[0,4],[1, 3],[2,1],[3,4]], label:'t4'}
];

$.plot($("#placeholder"), data, {
    series: {
        lines: {
            fill: true,
        },
        bars: {
            show: true,
            align:'center',
            barWidth: 0.8,
        }   
    },
    xaxis: {
        ticks: [[0, "Jan"],[1, "Feb"],[2, "Mar"],[3, "Apr"]]
    },
    yaxis: {
        min: 0
    }
});

The above code return the output

Example fiddle. enter image description here

How to get the below bar chart shows individual color for t1, t2, t3, t4 to corresponding month?... Based on this output what are the changes need in the code?... enter image description here

1

There are 1 best solutions below

0
user1731940 On

The below code working to shows bar char individual color

var data = [
    {data: [[0, 5],[1,2],[2,4],[3,1]], label:'t1'},
    {data: [[0.2,2],[1.2, 5],[2.2,2],[3.2,3]], label:'t2'},
    {data: [[0.4,3],[1.4, 7],[2.4,5],[3.4,2]], label:'t3'},
    {data: [[0.6,4],[1.6, 3],[2.6,1],[3.6,4]], label:'t4'}
];

$.plot($("#placeholder"), data, {
    series: {
        lines: {
            fill: true,
        },
        bars: {
            show: true,
            align:'center',
            barWidth: 0.1,
        }   
    },
    xaxis: {
        ticks: [[0.3, "Jan"],[1.3, "Feb"],[2.3, "Mar"],[3.3, "Apr"]]
    },
    yaxis: {
        min: 0
    }
});

But default data value shows data = [{data:[[0,5]], label:'t1'}, data:[[0,2]], label:'t1'}, data:[[0,3]], label:'t1'}];

How to update the data value for x axis 0, 0, 0 into 0, 0.2, 0.4, 0.6 dynamically?...