简体   繁体   中英

How can I color the dynamic data of the pie chart using morris js?

I fetched the data from the database and with the help of Morris JS I showed it on Donut pie chart. But the color of the pie chart sections seems similar . How can I change the color of the different section in pie chart.

Here is the Code :

$row->execute(); 
$json_data=array();  
foreach($row as $rec)  
{  
$json_array['label']=$rec['user_type'];  
$json_array['value']=$rec['id']; 

array_push($json_data,$json_array);  
}  

{ ?>    
<div id="donut-example" style="height: 250px;"></div>

<script type="application/javascript">

Morris.Donut({
element: 'donut-example',
data: <?php echo json_encode($json_data)?>
});

</script>

And here is the result Image : 饼图由莫里斯

please tell me how can I change the color in different section of the Pie Chart.

As per the Morris Donut example , you need to provide an array of colours:

Morris.Donut({
 colors: [
    '#0BA462',
    '#39B580',
    '#67C69D',
    '#95D7BB'
  ]
});

There is the ability also to set the labelColor globally or individually (per datum).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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