【发布时间】:2015-04-03 16:08:03
【问题描述】:
我正在使用 Chart.js 在我的网站中绘制图表。问题是,如果数据值为 0,我需要更改图形数据的样式。
例如我有数组(array1),其中包含以下数据: 0; 0; 0.125; 0; 0; 0;
所以这会显示这样的聊天:
生成样式的代码是这样的:
function MoreChartOptions(){}
var ChartData = {
labels : labelsArray,
datasets : [{
fillColor : "rgba(52,152,219,1)",
strokeColor : "rgba(52,152,219,0.5)",
pointColor : "rgba(52,152,219,1)",
markerShape :"circle",
pointStrokeColor : "rgba(255,255,255,1.00)",
data : array1,
},
]};
ChartOptions= {canvasBackgroundColor:'rgba(255,255,255,1.00)',spaceLeft:12,spaceRight:12,spaceTop:12, ...
我的问题是:如果图表数据的值为 0,如何更改(如果可能)ChartOptions 样式(字体大小 - inGraphDataFontSize:12)?
我试过这个,但它不起作用:
ChartOptions=
{canvasBackgroundColor:'rgba(255,255,255,1.00)', ...
...,
for(a=0;a<array1.length;a++){array1[a] != 0 ? inGraphDataFontSize:12 : inGraphDataFontSize:5}, ...
非常感谢您的帮助。
【问题讨论】:
-
调试器显示的错误是这样的:“Uncaught SyntaxError: Unexpected token (”它在所有 ChatOptions 下划线
标签: javascript styles chart.js