正如主題所述,我只是想根據y軸的值自定義每個欄的顏色。nvd3.js - 根據值的範圍顯示多欄垂直圖表中每個欄的特定顏色
的價值顏色的範圍是:
- 0-50:綠色
- 50-75:黃
- 75-100:紅
我試圖尋找此Google上的主題很多,但找不到任何結果。
這個stackoverflow question是最接近我的答案,但它不適用於nvd3。如果是的話,請告訴我應該在哪個位置添加功能。
我的代碼如下: -
HTML: -
<nvd3 options="options" data="data2"></nvd3>
JS: -
/* Chart options */
$scope.options = { /* JSON data */
chart: {
type: 'multiBarChart',
height: 250,
showControls: false,
margin : {
top: 20,
right: 20,
bottom: 45,
left: 45
},
clipEdge: true,
duration: 500,
stacked: true,
xAxis: {
axisLabel: 'Time (ms)',
showMaxMin: false,
tickFormat: function(d){
return d3.format(',f')(d);
}
},
yAxis: {
axisLabel: 'Y Axis',
axisLabelDistance: -20,
tickFormat: function(d){
return d3.format(',.1f')(d);
}
}
},
// title options
title: {
enable: true,
text: 'Title for Line Chart'
},
// subtitle options
subtitle: {
enable: true,
text: 'Subtitle for simple line chart. Lorem ipsum dolor sit amet...',
css: {
'text-align': 'center',
'margin': '10px 13px 0px 7px'
}
},
// caption options
caption: {
enable: true,
html: 'Figure 1. Lorem ipsum dolor sit amet...',
css: {
'text-align': 'justify',
'margin': '10px 13px 0px 7px'
}
}
};
/* Chart data */
$scope.data2 = [{"key":"Thermal","values":[{"x":0,"y":44},{"x":1,"y":24},{"x":2,"y":66},{"x":3,"y":10},{"x":4,"y":33}]}];
嗨,大家好。請幫助我,因爲我試圖找到很多可能的方法,但無法找到同樣的成功。 – Sagar