从浮动图表获取数据系列的颜色 [英] Getting color of a data series from a flot chart

查看:63
本文介绍了从浮动图表获取数据系列的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在stackoverflow用户页面上看到了一个很酷的新声誉"选项卡之后,我受到启发,开始使用Flot图表库.我有一个包含数百个系列的折线图.在任何给定时间,这些系列中只有几个是可见的.我的数据系列分为几个类别",我根据该类别分配数字颜色索引.我希望能够查看Flot为特定颜色索引值分配的实际颜色,其最终目的是创建将颜色与我的类别"数据相关联的自定义图例.如何获得这些颜色值?

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?

我看到我可以提供自己的颜色数组,但是我不愿意这样做,因为在加载数据之前,我不确定会拥有多少个类别.我想我可以创建一个行进太大的数组,但是如果可以问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.

推荐答案

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);

这篇关于从浮动图表获取数据系列的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆