Boby Rotka
Boby Rotka

Reputation: 71

Highchart pie - array dynamic for dynamic pie

Below my code :

$(document).ready(function() {
    for(var j = 0; j < productsSize; j++) {
        //tmStringToDisplay.push(name[j], parseInt(percent[j]));
        var tmStringToDisplay = [name[j], parseInt(percent[j])];
        tmStringToDisplay.push(temp);
    }
    console.log(tmStringToDisplay);

    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: {
            text: 'The best selling products :'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage}%</b>',
            percentageDecimals: 1
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    color: '#000000',
                    connectorColor: '#000000',
                    formatter: function() {
                        return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
                    }
                }
            }
        },



        series: [{
            type: 'pie',
            name: 'Product share',
            data: tmStringToDisplay
        }]
    });

I have to make the "tmStringToDisplay" tab, to put it in the data var of the series array. In static, it is like that :

series: [{
            type: 'pie',
            name: 'Browser share',
            data: [
                ['Firefox',   45.0],
                ['IE',       26.8],
                {
                    name: 'Chrome',
                    y: 12.8,
                    sliced: true,
                    selected: true
                },
                ['Safari',    8.5],
                ['Opera',     6.2],
                ['Others',   0.7]
            ]
        }]

That's in the loop FOR that all is working :

for(var j = 0; j < productsSize; j++) {
        //tmStringToDisplay.push(name[j], parseInt(percent[j]));
        var tmStringToDisplay = [name[j], parseInt(percent[j])];
        tmStringToDisplay.push(temp);
    }

I have to create and prepare the "tmStringToDisplay" which need to be like the static example....

Thank you !

Upvotes: 1

Views: 690

Answers (1)

karthik - LK
karthik - LK

Reputation: 915

parse the tmStringToDisplay to json

eg jQuery.parseJSON(tmStringToDisplay);

Upvotes: 1

Related Questions