【发布时间】:2019-10-09 11:57:48
【问题描述】:
我想通过我使用 Highcharts 的 rails 项目中的图表来表示数据。我能够将其整合到项目中。如果 y 轴值为零,我不想绘制图形。 Image reference of the current scenario
我的代码,
@chart_data = [[2015, 20], [2016, 31], [2017, 5], [2018, 19], [2019, 0]]
= column_chart @chart_data, height: '375px', library: {
xAxis: {
title: { text: 'Years'}
},
yAxis: {
stackLabels: {
enabled: true, style: {color: '#8b9196'}
},
title: {
text: 'Turn over rate')
}
},
plotOptions: {
column: {
dataLabels: {
enabled: true, style: { color: 'white'}
}
}
},
legend: {
align: 'right', x: 0, verticalAlign: 'top', y: -10, floating: true, backgroundColor: 'white', borderColor: '#CCC', borderWidth: 1, shadow: false
}
}
我发现 JavaScript 格式的解决方案没用。根据搜索,应添加如下代码
plotOptions: {
column: {
dataLabels: {
enabled: true, style: { color: 'white'},
formatter: %|function(){
if (this.y > 0)
return this.y;
}|
}
}
}
它抛出错误refer to the image here。我无法弄清楚获得所需结果的方法。我在 rails 中寻求帮助,因为图表已添加到视图中。
【问题讨论】:
-
嗨@Aditya Tiwari,Highcharts 要求
formatter属性是可以调用的JS 函数。 -
嗨@ppotaczek,我试过了,但它抛出错误。我已添加包含错误的图像。
-
很抱歉,因为我不懂ruby,所以真的很难帮你。
标签: json charts highcharts ruby-on-rails-5 slim-lang