morrisjs / morris.js

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

How to use bar chart data for donut chart? #679

Open nixis opened 8 years ago

nixis commented 8 years ago

Hi,

I need your help! I use this data at a bar chart, now I want to use the same data for a donut chart

data: [{"meals":19,"drinks":17}]

I know there is a formatter function, but I do not understand this.

Is there no chance like at the bar chart to set the keys and labels?

xkey: 'date', ykeys: ['meals', 'drinks'], labels: ['Meals', 'Drinks'],

Hope anybody has a tip for me :)

satyendrakumarsingh commented 7 years ago

If you are fetching these data from the server as simple variable then simply put those variable value in label and value Ex-

{label: "labelVarName", value: valueVarName}

If you have JSON data from your server then convert that JSON data in JS associative array and in Donut Chart simply access associative array and assign key as label and value as value.