[英]In HighCharts, how can I make the color for each plotted point in an array dependent on a value in a corresponding array?
For example say the array I would like to graph is [3,4,6,4,2,1,2] and the corresponding color array is [1,2,1,3,2,2,2] where 1=red,2=blue,3=green etc. I could change the array to ['red','blue','red' ...] if that helps. 例如,说我想绘制的数组是[3,4,6,4,2,1,2],相应的颜色数组是[1,2,1,3,2,2,2]其中1 = red,2 = blue,3 = green等。如果有帮助,我可以将数组更改为['red','blue','red'...]。
Is there any way to get the points to display with the proper color using an array? 有什么办法可以使用数组以正确的颜色显示点?
Thank you for your help! 谢谢您的帮助!
You can specify the points as arrays or objects and associate a correct color with the point. 您可以将点指定为数组或对象,并将正确的颜色与该点关联。
The use of an array and the series.keys property: 使用数组和series.keys属性:
series: [{
type: 'scatter',
keys: ['y', 'color'],
data: [[3, 'red'],[4, 'blue'],[6, 'red'], [4, 'green'],[2, 'blue'],[1, 'blue'],[2, 'blue']]
}],
example: http://jsfiddle.net/8u3q6omm/ 例如: http : //jsfiddle.net/8u3q6omm/
Objects: 对象:
series: [{
type: 'scatter',
data: [{y: 3, color: 'red'},{y: 4, color: 'blue'},{y: 6, color: 'red'}, {y: 4, color: 'green'},{y: 2, color: 'blue'},{y: 1, color: 'blue'},{y: 2, color: 'blue'}]
}],
example: http://jsfiddle.net/8u3q6omm/1/ 示例: http : //jsfiddle.net/8u3q6omm/1/
If you have any pattern for the values and the color, you can write a function for associating the color or use Highcharts zones . 如果您有用于值和颜色的任何图案,则可以编写用于关联颜色的函数或使用Highcharts zone 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.