Flot 0.8.2 Line Chart - Color Bug

2019-05-17 19:01发布

问题:

I was working with Flot line charts and setting their colors. I found an odd bug. After the first 3 colors, the plot uses the last color for all of the other lines. This is not the correct behavior.

What makes this even more interesting is that the legend displays the correct colors. Is this a known bug?

var dataSet = [
        {label: "d1", data: demand},
        {label: "d2", data: demand2},
        {label: "d3", data: demand3},
        {label: "d4", data: demand4},
        {label: "d5", data: demand5},
        {label: "d6", data: demand6}
    ]

$.plot(placeholder2, dataSet, {
    series: { 

    },
    legend: {
        noColumns: 0,
        position: "nw"
    },
    colors:["#2980B9","#D35400","#F39C12","#7F8CFF","#C0392B","#7F8C8D"]
});

Just to make sure that I wasn't going crazy, and to confirm, I tried the code again, but removed the colors specification. You'll see that even with Flot's default colors, the last color "sticks".

回答1:

Looks like the bug was a result of how I had the code setup. When I removed the series:{} code, it seems to work correctly.

The bug may be my fault, but that kind of repetitive behavior might need to be looked into.

$.plot(placeholder2, dataSet, {
    legend: {
        noColumns: 0,
        position: "nw"
    },
    colors:["#2980B9","#D35400","#F39C12","#7F8CFF","#C0392B","#7F8C8D"]
});