简体   繁体   English

每个scaleLine的chart.js雷达scaleShowLine

[英]chart.js radar scaleShowLine for each scaleLine

I'm working on a radar chart and I would like to only show the last scaleline. 我正在处理雷达图,我只想显示最后的比例尺。

I found this post which could have helped me: Chart.js (Radar Chart) different scaleLineColor for each scaleLine but unfortunately, the answer is not working anymore (the jsfiddle link doesn't display anything). 我发现这篇文章可能对我有帮助: Chart.js(雷达图)为每个scaleLine使用不同的scaleLineColor,但不幸的是,答案不再起作用了(jsfiddle链接不显示任何内容)。

I read parts of the chart.js documentation about gridLines option, then did some tests/changes on this code: [regular radar chart][2] without any result, would anyone know how to adjust it? 我阅读了chart.js文档中有关gridLines选项的部分,然后对该代码进行了一些测试/更改:[常规雷达图] [2]没有任何结果,有人知道如何调整它吗?

Thanks! 谢谢!

[2]: https://codepen.io/grayghostvisuals/pen/xmBpL enter code here [2]: https//codepen.io/grayghostvisuals/pen/xmBpL enter code here

Here is a solution using the latest version of chart.js ( v2.5.0 ). 这是使用最新版本的chart.js( v2.5.0 )的解决方案。 It uses the scale afterTickToLabelConversion callback property to overwrite the values that were set for the scale ticks (eg scale lines). 它使用刻度afterTickToLabelConversion回调属性来覆盖为刻度刻度设置的值(例如刻度线)。

Since you only want to display the last line, you have to overwrite them by keeping the first tick value (which is never displayed) and only the last tick value (the last line). 由于只想显示最后一行,因此您必须通过保留第一个刻度值(从不显示)和仅最后一个刻度值(最后一行)来覆盖它们。 If you only wanted to display some other line then you would keep the first tick and only the other line that you want displayed. 如果只想显示其他行,则保留第一个刻度,只保留要显示的其他行。

Here is my implementation. 这是我的实现。

afterTickToLabelConversion: function(scaleInstance) {
  // overwrite the ticks and keep the first (never shown) and last
  var oldTicks = scaleInstance.ticks;
  scaleInstance.ticks = [oldTicks[0], oldTicks[oldTicks.length - 1]];

  // overwrite the numerical representation of the ticks and 
  // keep the first (never shown) and last
  var oldTicksAsNumbers = scaleInstance.ticksAsNumbers;
  scaleInstance.ticksAsNumbers = [oldTicksAsNumbers[0], oldTicksAsNumbers[oldTicksAsNumbers.length - 1]];
}

Here is a codepen example that shows an original radar chart and one using the approach described above so that you can see the difference. 这是一个Codepen示例 ,显示了原始雷达图和一个使用上述方法的雷达图,您可以看到其中的区别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM