我将Flotcharts与PHP一起使用。我面临两个问题
- 我想在 Y 轴上以良好的格式表示数字,例如1500必须显示为1,500等等。我知道 php 函数
number_format()
,但如果我number_format()
在绘制图表时通过,萤火虫会引发解析错误。请参阅下面标题ISSUE-1下的代码并检查echo number_format(6443.230356)
- 如果 Y 轴的值是从 ( 1 到 9 ),那么当前它显示为 ( 1, 2 .. 9 )。我想将这些值表示为 ( 1.0, 2.0, 3.0, ... 9.0 )
问题一
<script>
plotOptions = {
"colors":["#edaf40","#999","#edaf3e","#ec8","#9cc","#dad","#9ce","#fca"],
"grid":{
"labelMargin":0,
"tickColor":"#e3e3e3",
"backgroundColor":"#f2f2f2",
"borderWidth":0.5,
"hoverable":true,
"autoHighlight":true,
"clickable":false,
"color":"#bbb"
},
"bars": { show: true, barWidth: 0.85, series_spread: true, align: "center","lineWidth": 0.3,fillColor:{colors: [ { opacity: 1 }, { opacity: 1 } ] } },
"lines":{"show":false,"lineWidth":1.25,"fill":0},
"points":{"show":false,"radius":2,"lineWidth":2,"fill":1},
"shadowSize":1,
"yaxis":{"min":0,"max":<?php echo number_format(6443.230356)?>,axisLabel: '',axisLabelUseCanvas: false,axisLabelFontSizePixels: 12,axisLabelFontFamily: 'Verdana, Arial, Helvetica, Tahoma, sans-serif',axisLabelPadding: 5},
"xaxis":{"min":"1989","max":"2016","tickSize":5,"tickLength": 0, "ticks": 0.1},
zoom: {
interactive: true
}
};
</script>
我也试过"max":'<?php echo number_format(6443.230356)?>'
,但这次萤火虫说不是数字错误。
NaN
并且
我搜索了他们的网站,但没有找到解决方案。请指导如何解决。
为了解决第 2 点,我尝试了
function suffixFormatter(val) {
if (val >= 1)
return val.toFixed(yaxis.tickDecimals) + " 0";
else if (val <= 9)
return val.toFixed(yaxis.tickDecimals) + " 0";
else
return val;
}
"yaxis":{"function":suffixFormatter(<?php echo $min_val;?>), "min":<?php echo $min_val;?>,"max":<?php echo (1.2*$yaxismax);?>,axisLabel: '<?=$indicatorData[0]->unit?>',axisLabelUseCanvas: false,axisLabelFontSizePixels: 12,axisLabelFontFamily: 'Verdana, Arial, Helvetica, Tahoma, sans-serif',axisLabelPadding: 5},
但发生错误yaxis is not define
tickDecimals is not define
。
我对FlotChart支持真的很失望,它非常糟糕,没有合适的示例代码,没有合适的指南。请有人指导我吗?