我有一个创建折线图的功能。我给它一个布尔参数来判断我是否需要小数。然后我做:
if($decimal)
$format = "{point.y:.2f}";
else
$format = "{y}";
并在创建图表时:
plotOptions: {
line: {
dataLabels: {
enabled: true,
format: ".$format."
}
}
但它不起作用。如果我代之以".$format."
而不是'{point.y:.2f}'
,那么它可以正常工作
我需要指出“......”不是问题,因为我将它用于其他一些选择。
我的错误在哪里?
答案 0 :(得分:0)
我猜你需要在包含变量之前将值包装在引号中。
所以,这个:
plotOptions: {
line: {
dataLabels: {
enabled: true,
format: ".$format."
}
}
成为这个:
plotOptions: {
line: {
dataLabels: {
enabled: true,
format: '".$format."'
}
}
你应该得到某种javascript错误但是......是吗?
答案 1 :(得分:0)
看看你如何在php http://docs.highcharts.com/#preprocessing-data-from-a-database中使用它,如果你使用双引号,你不需要使用点,所以它应该是“$ format”。更多如果您尝试将“{point.y:.2f}”粘贴为字符串,它将无法工作,因为它不是JSON。我建议使用formatter来定义带前缀的返回函数。