Is it possible to shorten outer labels on Radar graph using Chart.js, without affecting the other labels?

时间:2016-05-11 11:29:14

标签: javascript chart.js

I'm currently using Chart.js and building a radar graph in my project with some dynamic data. It is working fine. However, the users occasionally use too many characters in their labels and this affects the overall size of the graph.

Is there a way of reducing the outer ring labels to say:

"This is a really long label" to "This is a ... "

Without affecting the label within the graph itself (the hover label)?

I did think of something like:

var label = "This is a really long label";
newLabel = label.substring(0,8) + "...";


Giving: This is ...

However this will affect both the label on the outside of the radar graph and also the interior hover label. I just want the outer label fixed.

1 个答案:

答案 0 :(得分:0)

只需设置scaleLabel功能

即可
...
options: {
   scale: {
      pointLabels: {
         callback: function(pointLabel) {
           if (pointLabel.length > 6)
              return pointLabel.substring(0, 5) + '...';
           else 
              return pointLabel
         }
      }
   }
}
...

小提琴 - http://jsfiddle.net/e7suv6jg/

相关问题