简体   繁体   English

在HighCharts中,如何使数组中每个绘制点的颜色取决于相应数组中的值?

[英]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.

相关问题 如何找到所有点的2D numpy数组中的点大于参考数组中的对应点的百分比? - How can I find the percentage of times that a point in a 2D numpy array is greater than the corresponding point in a reference array, for all points? 我如何在C中的char数组上的char指针(指向)上复制相同的值? - how can I make a copy the same value on char pointer(its point at) from char array in C? 考虑到这些值中的每一个都有唯一的对应值,如何在数组中随机显示值? - How do I randomly display values within an array considering that each of these values has a unique corresponding value? 当每个值也是一个数组时,如何翻转数组? - How can I flip an array when each value is also an array? 如何使结构指向前一个数组值 - How to make struct point to previous array value 如何使数组变量指向另一个数组,从而将第二个数组的内容有效地复制到第一个数组中? - How can I make an array variable point to a different array, effectively copying the contents of the second array into the first? 如何使用javascript或angular将一个数组的每个元素添加到其他数组中的对应元素 - How can I add each element of one array to corresponding elements in other arrays with javascript or angular 我怎样才能使数组中的字段值与数组索引相同 - how can i make a field value in an array the same as the array index 如何将输入值与数组的每个值进行比较? - How can I compare an input value with each value of an array? 如何遍历对象数组以返回依赖于 object 中相应属性的属性? - How do I loop over an array of objects to return a property dependent on a corresponding property within that object?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM