我使用canvasJS制作折线图报告,现在的问题是它在使用yValueFormatString
的工具提示中没有正确显示。
我的目标是显示价值:
{
type:"stepLine",
name: "title",
showInLegend: true,
connectNullData: true,
yValueFormatString: "##.## %",
dataPoints: [
{ x: new Date(2019, 1, 20), y: 12.78 },
{ x: new Date(2019, 1, 19), y: 12.79 },
{ x: new Date(2019, 1, 18), y: 12.80 },
]
}
在工具提示中,它显示
1278 %
1279 %
1280 %
我觉得它有问题,我想显示如下:
12.78 %
12.79 %
12.80 %
任何的想法?
根据documentation,“%”将数字乘以100,即12.78("##.## %") => 1278%
。相反,在这种情况下设置yValueFormatString to "##.#0 '%'"
应该可以正常工作。
这是一个例子:
var chart = new CanvasJS.Chart("chartContainer", {
data: [{
type:"stepLine",
name: "title",
showInLegend: true,
connectNullData: true,
yValueFormatString: "##.#0 '%'",
dataPoints: [
{ x: new Date(2019, 1, 20), y: 12.78 },
{ x: new Date(2019, 1, 19), y: 12.79 },
{ x: new Date(2019, 1, 18), y: 12.80 },
]
}]
});
chart.render();
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<div id="chartContainer" style="width: 100%; height: 260px"></div>