gpt4 book ai didi

javascript - 更改具有阈值的条形图的颜色

转载 作者:行者123 更新时间:2023-12-03 12:31:56 25 4
gpt4 key购买 nike

在 Jqplot 中,我只有一系列数据,但阈值为 200。我需要更改颜色,如下所示。这怎么可能? series of data having threshold value

最佳答案

一种方法是定义根据您的数据值定义的颜色数组。

为此,您可以在绘制图表之前进行预处理。您需要迭代数据并根据阈值在颜色数组中添加红色或蓝色:

var data = [['Nissan', 4],['Porche', 6],['Acura', 2],['Aston Martin', 5],['Rolls Royce', 6]];
var colors = [];
var threshold = 5;
$.each(data, function(index, value){
if(value[1] > threshold)
colors.push("#FF0000");
else
colors.push("#0000FF");
});

请参阅工作示例 here on jsfiddle

关于javascript - 更改具有阈值的条形图的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23885107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com