morrisjs / morris.js

Pretty time-series line graphs
http://morrisjs.github.com/morris.js/
6.92k stars 1.23k forks source link

style donut chart label wrap #547

Open tvrajja opened 9 years ago

tvrajja commented 9 years ago

how to display multiline label if label length is more. if label is more is not able to read properly. Education & Vocational Rehabilitation/ Employment is displayed in one line, i want to display this label as two / three line label.

code; var TotalExp = 62; Morris.Donut({ element: 'donut-example', data: [ {label: "Download Sales", value: 12}, {label: "In-Store Sales", value: 30}, {label: "Education & Vocational Rehabilitation/ Employment", value: 20} ],

formatter: function (x) { return Math.floor(x) } });

Seethala14 commented 6 years ago

Please can anyone provide solution for this issue. Me too face same difficulty.

awaisaly commented 6 years ago

I've solved my issue with this because there is no formatter for label in donut chart.

` //for truncating string after specified character String.prototype.trunc = String.prototype.trunc || function (n) { return (this.length > n) ? this.substr(0, n - 1) : this; };

var inputData = [ {label: "Download Sales", value: 12}, {label: "In-Store Sales", value: 30}, {label: "Education & Vocational Rehabilitation/ Employment", value: 20} ];

for (var i = 0; i < brandData.length; i++) { // here instead of 11 you can put any number you want to show actually this is the number of characters inputData[i].label = inputData[i].label.trunc(11) + ".."; }

pie_brand = Morris.Donut({ element: 'pie_brand', data: inputData , responsive: true, formatter: function (x, data) { return x + "%" } });`