How to change color of bar in column chart with different level of percentage in highcharts -


i want change color of bar column @ different percentage. suppose there 10 columns represented in column graph. out of 3 below 60% , 5 above 60% , 2 above 80%. columns below 60% should pick color green, column above 60% should pick color amber , above 80% should pick red. please me...


<!doctype html> <html>     <head>         <meta http-equiv="content-type" content="text/html; charset=utf-8">         <title>highcharts example</title>          <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>         <script> $(function () {     var chart;    var input = [34.4, 62.5, 80.1, 70, 69.6, 69.5, 89.1, 68.4, 18,                     17.3],     data = [],     categories = ['orcl1 ','orcl2 ','orcl3 ','orcl4 ','orcl5 ','orcl6 ','orcl7 ','orcl8 ','orcl9 ','orcl10 '];     $.each(input, function(index, value){         var color;         if (value > 80) color = 'red';         else if (value > 60) color = 'orange';         else color = 'green';         data.push({y:value, color: color, url:'https://www.google.com'});     });      $(document).ready(function() {         chart = new highcharts.chart({             chart: {                 renderto: 'col',                 type: 'column'             },             title: {                 text: 'current top 10 cpu consumers',                     style: {fontsize: '10px'}             },             xaxis: {                 categories: categories,                 labels: {                     rotation: -35,                     align: 'center'                 }             },            yaxis: {                 title: {                     text: 'percentage',                     style: {fontsize: '11px'}                 }             },             exporting: { enabled: false },              legend: {                 enabled: false,             },             tooltip: {                 formatter: function() {                     return '<b>'+ this.x +'</b>' +'- oracle user process cpu consumed :'+'<b>'+ this.y +' % ' +'</b>' ;                 }             },        plotoptions: {             series: {                 cursor: 'pointer',                 point: {                     events: {                         click: function() {                             location.href = this.options.url;                         }                     }                 }             }         },                 series: [{                 name: 'cpu consumed',                 pointwidth: 28,                 data: data              }]         });     }); });           </script>     </head>     <body> <script src="../../js/highcharts.js"></script> <script src="../../js/modules/exporting.js"></script>  <div id="col" style="min-width: 100px; height: 300px; margin: 0 auto"></div>      </body> </html> 

you'll need preprocess data assign colors. this:

var input = [34.4, 62.5, 80.1, 70, 69.6, 69.5, 89.1, 68.4, 18,                 17.3], data = []; $.each(input, function(index, value){     var color;     if (value > 80) color = 'red';     else if (value > 65) color = 'yellow';     else color = 'green';     data.push({y:value, color: color}); }); 

http://jsfiddle.net/btwcb/


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -