Getting color of a data series from a flot chart

那年仲夏 提交于 2019-12-21 09:53:49

问题


After seeing the cool new "reputation" tab on the stackoverflow 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?

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.


回答1:


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

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


来源:https://stackoverflow.com/questions/173205/getting-color-of-a-data-series-from-a-flot-chart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!