pie chart slice colour using color Value - Javascript highcharts

Javascript examples for highcharts:Chart Value

Description

pie chart slice colour using color Value

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"></script> 
      <script type="text/javascript">
$(function () {//from  ww  w.ja v a  2s .  co m
    var getColor = function (step,stepCount) {
        var scaledHex = Math.floor(255*step/(stepCount+1)).toString(16);
        console.log(scaledHex);
        return '#FF'+scaledHex+scaledHex;
    };
    $('#container').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: {
            text: 'Browser market shares at a specific website, 2014'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
            }
        },
        colorAxis: {
            minColor: '#FFFFFF',
            maxColor: '#FF0000'
        },
        series: [{
            type: 'pie',
            name: 'Browser share',
            data: [
                {
                    name: 'Firefox',
                    y: 45.0,
                    color: getColor(1,3)
                },
                {
                    name: 'IE',
                    y: 26.8,
                    color: getColor(2,3)
                },
                {
                    name: 'Chrome',
                    y: 12.8,
                    color: getColor(3,3)
                }
            ]
        }]
    });
});

      </script> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <script src="https://code.highcharts.com/modules/exporting.js"></script> 
      <div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>  
   </body>
</html>

Related Tutorials