Javascript 基于从另一个数据集计算的范围的彩色条形图
对于Javascript 基于从另一个数据集计算的范围的彩色条形图,javascript,jquery,c3.js,Javascript,Jquery,C3.js,对于t2actual中的每个值,我将根据critera范围为条形图上色。我希望获得与t2setpoint相同索引中的值,并使用算术来计算我的高点和低点,而不是常数,如下所示: colors: { t2setpoint: '#77777a', drybulb: '#4d4d4f', t2actual: function(d) { if (
t2actual
中的每个值,我将根据critera范围为条形图上色。我希望获得与t2setpoint
相同索引中的值,并使用算术来计算我的高点和低点,而不是常数,如下所示:
colors: {
t2setpoint: '#77777a',
drybulb: '#4d4d4f',
t2actual:
function(d) {
if (d.value >= 44.5 && d.value <= 45.5) {
return '#218340';
} else if (d.value >= 44.0 && d.value <= 44.4 || d.value >= 45.6 && d.value <= 50) {
return '#f7b731';
} else {
return '#f7b731';
}
}
},
对于上述计算,如何获得与t2actual(t2act)
中的值处于同一索引中的t2设定点(t2set)
的值
整个代码:
(function($) {
"use strict";
var chart = c3.generate({
data: {
columns: [
// each columns data
['t2setpoint', 45.1, 45, 45.4, 45, 45.2, 45, 45, 45, 45, 48.1, 45, 45, 45, 45, 45.1, 46, 46, 46],
['drybulb', 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3],
['t2actual', 44, 45, 45, 46, 47, 46, 45, 45, 45, 44, 45, 46, 45, 47, 46, 45, 44, 45]
],
axes: {
t2setpoint: 'y',
drybulb: 'y',
t2actual: 'y2'
},
type: 'bar', // default type of chart
types: {
't2setpoint': "spline",
'drybulb': "spline",
},
groups: [
['t2actual']
],
colors: {
t2setpoint: '#77777a',
drybulb: '#4d4d4f',
t2actual:
function(d) {
if (d.value >= 44.5 && d.value <= 45.5) {
return '#218340';
} else if (d.value >= 44.0 && d.value <= 44.4 || d.value >= 45.6 && d.value <= 50) {
return '#f7b731';
} else {
return '#f7b731';
}
}
/*
t2actual:
function(t2act) {
if (t2act.value >= t2set.value - 0.5 && t2act.value <= t2set.value + 0.5) {
return '#218340';
} else if (t2act.value >= t2set.value - 1 && t2act.value <= t2set.value + 1) {
return '#f7b731';
} else {
return '#a62337';
}
}
*/
},
axis: {
x: {
type: 'category',
label: {
text: '',
position: 'outer-center'
},
tick: {
rotate: -75,
multiline: false
},
height: 70,
categories: [1', 2', 3', 4', 5', 6', 7', 8', 9', 10', 11', 12', 13', 14', 15', 16', 17', 18']
},
y: {
min: 30,
max: 100,
label: {
text: 'Dry Bulb',
position: 'outer-middle'
}
},
y2: {
min: 30,
max: 100,
show: true,
label: {
text: 'T2 Actual',
position: 'outer-middle'
}
}
},
bar: {
width: 50
},
legend: {
show: true, //hide legend
},
padding: {
bottom: 0,
top: 0,
},
});
})(jQuery);
(函数($){
“严格使用”;
var图表=c3.0({
数据:{
栏目:[
//每列数据
['t2setpoint',45.1,45,45.4,45,45,45.2,45,45,45,45,48.1,45,45,45,45,45,45,45,45,45,45,45,45.1,46,46],
[干球',82.3,82.3,82.3,82.3,82.3,82.3,82.3,82.3,82.3,82.3,82.3,82.3,82.3,82.3,82.3,82.3,82.3,82.3],
[t2actual',44,45,45,46,47,46,45,45,45,44,45,46,45,47,46,45,45]
],
轴线:{
t2设定点:“y”,
干球茎:“y”,
t2实际值:“y2”
},
类型:'条形图',//图表的默认类型
类型:{
“t2setpoint”:“样条曲线”,
“干球”:“样条曲线”,
},
小组:[
['t2actual']
],
颜色:{
t2设定值:“#77777 A”,
干球:“#4D4F”,
t2实际:
职能(d){
如果(d.value>=44.5&&d.value=44.0&&d.value=45.6&&d.value=t2set.value-0.5&&t2act.value=t2set.value-1&&t2act.value
(function($) {
"use strict";
var chart = c3.generate({
data: {
columns: [
// each columns data
['t2setpoint', 45.1, 45, 45.4, 45, 45.2, 45, 45, 45, 45, 48.1, 45, 45, 45, 45, 45.1, 46, 46, 46],
['drybulb', 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3, 82.3],
['t2actual', 44, 45, 45, 46, 47, 46, 45, 45, 45, 44, 45, 46, 45, 47, 46, 45, 44, 45]
],
axes: {
t2setpoint: 'y',
drybulb: 'y',
t2actual: 'y2'
},
type: 'bar', // default type of chart
types: {
't2setpoint': "spline",
'drybulb': "spline",
},
groups: [
['t2actual']
],
colors: {
t2setpoint: '#77777a',
drybulb: '#4d4d4f',
t2actual:
function(d) {
if (d.value >= 44.5 && d.value <= 45.5) {
return '#218340';
} else if (d.value >= 44.0 && d.value <= 44.4 || d.value >= 45.6 && d.value <= 50) {
return '#f7b731';
} else {
return '#f7b731';
}
}
/*
t2actual:
function(t2act) {
if (t2act.value >= t2set.value - 0.5 && t2act.value <= t2set.value + 0.5) {
return '#218340';
} else if (t2act.value >= t2set.value - 1 && t2act.value <= t2set.value + 1) {
return '#f7b731';
} else {
return '#a62337';
}
}
*/
},
axis: {
x: {
type: 'category',
label: {
text: '',
position: 'outer-center'
},
tick: {
rotate: -75,
multiline: false
},
height: 70,
categories: [1', 2', 3', 4', 5', 6', 7', 8', 9', 10', 11', 12', 13', 14', 15', 16', 17', 18']
},
y: {
min: 30,
max: 100,
label: {
text: 'Dry Bulb',
position: 'outer-middle'
}
},
y2: {
min: 30,
max: 100,
show: true,
label: {
text: 'T2 Actual',
position: 'outer-middle'
}
}
},
bar: {
width: 50
},
legend: {
show: true, //hide legend
},
padding: {
bottom: 0,
top: 0,
},
});
})(jQuery);