0

I have this fiddle here http://jsfiddle.net/rg6wczo6/ . I am basically formatting the plotoptions to display my numbers in m and k format highcharts does for y axis. I also want to have the chart as a pie chart but i am getting an error saying Cannot read property 'tickInterval' of undefined which suggests the yAxis. Can some one please tell me how I can make the formatting work for pie Charts also.

var options = {
                chart: {
                      renderTo: 'drillDown'
                },
                title: {
                    text: 'Healthcare Operations'
                },
                subtitle: {
                    text: 'Facility Revenue'
                },
                plotOptions: {
                    series: {
                        dataLabels: {
                            enabled: true,

                            formatter:
                                function () {                                

                                        var ret = '',
                                            multi,
                                            axis = this.series.yAxis,
                                            numericSymbols = ['k', 'M', 'G', 'T', 'P', 'E'],
                                            i = numericSymbols.length;
                                        while (i-- && ret === '') {
                                            multi = Math.pow(1000, i + 1);
                                            if (axis.tickInterval >= multi && numericSymbols[i] !== null) {
                                                ret = Highcharts.numberFormat(this.y / multi, -1) + numericSymbols[i];
                                            }
                                        }
                                        return this.point.name + ":" + ret;

                                }
                        }
                    }
                },

                series: [{
                    name: 'Facility',
                    colorByPoint: true,
                    data: mainData
                }],
                drilldown: {
                    series: [ {
                        name: 'Jacobs Medical Park',
                        id: 'Jacobs Medical Park',
                        data: jacobsMedicalParkData
                    }, {
                        name: 'Blue Star',
                        id: 'Blue Star',
                        data: blueStarData
                    }, {
                        name: 'Cigna',
                        id: 'Cigna',
                        data: cignaData
                    },
                    {
                        name: 'Blue Cross',
                        id: 'Blue Cross',
                        data: blueCrossData
                    }
                    ]
                }
            }
            options.chart.renderTo = 'drillDown';
            options.chart.type = 'column';
            var chart1 = new Highcharts.Chart(options);

            // Pie
            options.chart.renderTo = 'drillDown1';
            options.chart.type = 'pie';
            var chart2 = new Highcharts.Chart(options);

Thanks

SP1
  • 1,182
  • 3
  • 22
  • 47

2 Answers2

2

Using the function found here to convert number into metric notation string:

function intToString (value) {
    var suffixes = ["", "k", "m", "b","t"];
    var suffixNum = Math.floor((""+value).length/3);
    var shortValue = parseFloat((suffixNum != 0 ? (value / Math.pow(1000,suffixNum)) : value).toPrecision(2));
    if (shortValue % 1 != 0)  shortNum = shortValue.toFixed(1);
    return shortValue+suffixes[suffixNum];
}

You can do:

plotOptions: {
  pie: {
    dataLabels: {
      enabled: true,
      formatter: function() {
                console.log(this);
        return '<b>' + this.key + '</b>: ' + intToString(this.y);
      }
    }
  },

You can probably replace you existing code for the bar chart with a call to this function as well for code re-use/readability.

Sample jsFiddle.

Community
  • 1
  • 1
wergeld
  • 14,332
  • 8
  • 51
  • 81
  • 1
    Awesome..Thank you so much for the help. Just starting on highcharts so your help is much appreciated :). – SP1 Mar 11 '16 at 18:54
0

If I get it right, you want to dislpay the name of the slice along with the value? Add the follwing to your plotOptions if I am right.

pie: {
                enabled: true,
                formatter: function(){
                    If(this.y >= 1000){
                        return this.name + ' : ' + this.y/1000 + 'k';
                    }
                    return this.name + ' : ' + this.y;
                }
            }
        }
Rahul Sharma
  • 892
  • 1
  • 6
  • 16