Javascript jqPlot-基于系列中每个数据点的值范围的不同颜色条
我需要为一个系列中的每个数据点有条件地更改条形图的颜色。系列中的1个数据点需要具有与其他4个数据点不同的颜色阈值 我试图实现在中找到的建议,但是我得到了一个JS错误,该对象没有get方法 这是我正在处理的数据: 系列2需要有不同的颜色。制作这些系列的数据在这里Javascript jqPlot-基于系列中每个数据点的值范围的不同颜色条,javascript,jquery,jqplot,Javascript,Jquery,Jqplot,我需要为一个系列中的每个数据点有条件地更改条形图的颜色。系列中的1个数据点需要具有与其他4个数据点不同的颜色阈值 我试图实现在中找到的建议,但是我得到了一个JS错误,该对象没有get方法 这是我正在处理的数据: 系列2需要有不同的颜色。制作这些系列的数据在这里 阈值数据包含[[2,1]、[4,2]、[6,3]、[3,4]、[8,5]] 结果数据包含[[6,1]、[6,2]、[4,3]、[6,4]、[6,5]] 结果数据指的是蓝色条形图线,阈值数据指的是橙色线 对于元素4的结果中的元素1,我需要
如果要覆盖内部数组时,它的第一个元素是>=0和=5和=8,以及=0和=6和,那么应该实现它的所有方法。这是源代码,您需要实现
get
和setColors
方法
function (colors) {
colors = colors || $.jqplot.config.defaultColors;
var idx = 0;
this.next = function () {
if (idx < colors.length) {
return colors[idx++];
}
else {
idx = 0;
return colors[idx++];
}
};
this.previous = function () {
if (idx > 0) {
return colors[idx--];
}
else {
idx = colors.length-1;
return colors[idx];
}
};
// get a color by index without advancing pointer.
this.get = function(i) {
var idx = i - colors.length * Math.floor(i/colors.length);
return colors[idx];
};
this.setColors = function(c) {
colors = c;
};
this.reset = function() {
idx = 0;
};
this.getIndex = function() {
return idx;
};
this.setIndex = function(index) {
idx = index;
};
}
函数(颜色){
colors=colors | |$.jqplot.config.defaultColors;
var-idx=0;
this.next=函数(){
if(idx0){
返回颜色[idx--];
}
否则{
idx=颜色。长度-1;
返回颜色[idx];
}
};
//按索引获取颜色,而不推进指针。
this.get=函数(i){
var idx=i-colors.length*Math.floor(i/colors.length);
返回颜色[idx];
};
this.setColors=函数(c){
颜色=c;
};
this.reset=函数(){
idx=0;
};
this.getIndex=函数(){
返回idx;
};
this.setIndex=函数(索引){
idx=指数;
};
}
当您想要覆盖它时,应该实现它的所有方法。这是源代码,您需要实现get
和setColors
方法
function (colors) {
colors = colors || $.jqplot.config.defaultColors;
var idx = 0;
this.next = function () {
if (idx < colors.length) {
return colors[idx++];
}
else {
idx = 0;
return colors[idx++];
}
};
this.previous = function () {
if (idx > 0) {
return colors[idx--];
}
else {
idx = colors.length-1;
return colors[idx];
}
};
// get a color by index without advancing pointer.
this.get = function(i) {
var idx = i - colors.length * Math.floor(i/colors.length);
return colors[idx];
};
this.setColors = function(c) {
colors = c;
};
this.reset = function() {
idx = 0;
};
this.getIndex = function() {
return idx;
};
this.setIndex = function(index) {
idx = index;
};
}
函数(颜色){
colors=colors | |$.jqplot.config.defaultColors;
var-idx=0;
this.next=函数(){
if(idx0){
返回颜色[idx--];
}
否则{
idx=颜色。长度-1;
返回颜色[idx];
}
};
//按索引获取颜色,而不推进指针。
this.get=函数(i){
var idx=i-colors.length*Math.floor(i/colors.length);
返回颜色[idx];
};
this.setColors=函数(c){
颜色=c;
};
this.reset=函数(){
idx=0;
};
this.getIndex=函数(){
返回idx;
};
this.setIndex=函数(索引){
idx=指数;
};
}
系列颜色:值<阈值?[#ff0000]:[#00ff00] 系列颜色:值<阈值?[#ff0000]:[#00ff00] 我真不敢相信这有多明显。非常感谢。我真不敢相信这是多么明显。非常感谢。标记为已接受。您能为您的答案添加一些上下文吗?解释这解决了什么问题,以及为什么这回答了OP的原始问题。你能为你的答案添加一些上下文吗?解释这解决了什么问题,以及为什么回答OP的原始问题