morrisjs / morris.js

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

Morris Donut Chart label is showing undefined error #778

Closed ShajahanKP closed 5 years ago

ShajahanKP commented 5 years ago

Dear Friends,

I am using Morris Donut chart to display the progress. I am getting the count of status correctly. But instead of Label it is showing undefined in the donut chart. image

`var dtData = _.groupBy(jsonData, "status"); var keys = []; keys = Object.keys(dtData); alert(keys);

        dtArr = [];

        for (var n = 0; n < keys.length; n++) {

            dtArr.push({
                name: '' + keys[n] + '', value: '' + dtData[keys[n]].length + '',

            });

        } `

Morris.Donut({ element: 'dashboard-donut-8', data: dtArr, label: 'name', value: 'value', colors: ['#33414E', '#E04B4A', '#1caf9a', '#95b75d'], resize: true });

I am getting the value correctly. But getting as undefined for label.

Please help me on this

pierresh commented 5 years ago

You should use the key label instead of name

label: '' + keys[n] + '', value: '' + dtData[keys[n]].length + '',

ShajahanKP commented 5 years ago

You should use the key label instead of name

label: '' + keys[n] + '', value: '' + dtData[keys[n]].length + '',

I changed as shown below:

for (var n = 0; n < keys.length; n++) { `dtArr.push({ label: '' + keys[n] + '', value: '' + dtData[keys[n]].length + '',

            });`

} Morris.Donut({ element: 'dashboard-donut-8', data: dtArr, label: 'label', value:'value', colors: ['#33414E', '#E04B4A', '#1caf9a', '#95b75d'], resize: true });`

Is the right way ?? Kindly suggest

ShajahanKP commented 5 years ago

You should use the key label instead of name

label: '' + keys[n] + '', value: '' + dtData[keys[n]].length + '',

Thanks :+1:

Works properly :100: