Search code examples
javascriptflot

Flot: Order the stacking of the bars throughout screen with multiple stacked bar charts


Se the JSFIDDLE

Q: I need to order the stacked bars so it'll be consistent throughout a screen with multiple stacked bar charts.
e.g if one bar has stacked labels starting with the top to bottom 087, 084, 080, 01-02, 00 then the position should be the same in all the other charts

I've tried:

chartData.sort(function(a, b){ 
    return a.label.localeCompare(b.label);
});

But it does not seem to work for stacked labels in one bar.


Solution

  • There is a problem with the stacking when one data series in the chart has a gap at a specific x value. For example the middle bar (at x = 2) in chart 2:

    {
        label: "084",
        data: [
            [0, 3],
            [1, 12],
            [2, 0], // this was missing, after adding it, the stacking works
            [3, 53],
            [4, 13]
        ]
    }