Reputation: 6001
When I add a new series to the chart dynamically the same initial colour is applied, it should generate a new color as per documentation but it doesnt, is this a bug or am I doing something wrong?
I am using flot 0.8.2.
Update: I just saw this, it might be related:Flot 0.8.2 Line Chart - Color Bug
var serie1 ={label:"test",data:[[12,123],[15,125]]};
var serie2 ={label:"jonas",data:[[12,125],[15,123]]};
var flot = $.plot($("#container"),[serie1]);
var allData = flot.getData();
allData.push(serie2);
flot.setData(allData);
flot.setupGrid();
flot.draw();
Fiddle:http://jsfiddle.net/luisvsilva/knj8c/1/
Upvotes: 1
Views: 423
Reputation: 17550
Yeah, that's a little bit of a bug if you use flot in this way. When you use setData()
to add the second series, flot won't add new color because it starts again from the beginning of the automated color array which it already used for the first series.
(I will add more details to the bug ticket you opened.)
If you use flot = $.plot($("#container"), [serie1, serie2]);
instead you get the normal behavior you want.
Alternatively you can specify colors in you data like
var serie1 = { label: "test", data: [[12, 123], [15, 125]], color: 0 };
var serie2 = { label: "jonas", data: [[12, 125], [15, 123]], color: 1 };
Upvotes: 2