从flot图表中获取数据系列的颜色

时间:2022-06-24 20:06:23

After seeing the cool new "reputation" tab on the * user page, I was inspired to play with the Flot charting library a little. I have a line chart that has several hundred series. Only a couple of these series will be visible at any given time. My data series are grouped into several "categories" and I assign the numeric color index based on that category. I'd like to be able to see what actual color was assigned by Flot to a particular color index value, for the ultimate purpose of creating a custom legend that relates the color to my "category" of data. How can I get these color values?

在*用户页面上看到很酷的新“信誉”选项卡之后,我受到启发,可以稍微使用Flot图表库。我有一个有几百个系列的折线图。在任何给定时间,只有几个系列可见。我的数据系列分为几个“类别”,我根据该类别分配数字颜色索引。我希望能够看到Flot为特定颜色索引值分配的实际颜色,最终目的是创建将颜色与我的“数据类别”相关联的自定义图例。我怎样才能获得这些颜色值?

I see that I can provide my own array for colors, but I am reluctant to do this, because I am not sure how many categories I will have until I load the data. I suppose I could just create an array that's just way too big, but that seems wasteful if it's possible to ask Flot what color each series is.

我看到我可以提供自己的颜色数组,但我不愿意这样做,因为我不确定在加载数据之前我会有多少类别。我想我可以创建一个太大的数组,但是如果可以问Flot每个系列是什么颜色那么这似乎很浪费。

1 个解决方案

#1


14  

There's an example at the bottom of http://flot.googlecode.com/svn/trunk/API.txt that does just that. Something like:

http://flot.googlecode.com/svn/trunk/API.txt底部有一个例子就是这样。就像是:

var plot = $.plot(placeholder, data, options)
var series = plot.getData();
for (var i = 0; i < series.length; ++i)
   alert(series[i].color);

#1


14  

There's an example at the bottom of http://flot.googlecode.com/svn/trunk/API.txt that does just that. Something like:

http://flot.googlecode.com/svn/trunk/API.txt底部有一个例子就是这样。就像是:

var plot = $.plot(placeholder, data, options)
var series = plot.getData();
for (var i = 0; i < series.length; ++i)
   alert(series[i].color);

相关文章