2

getting data from php page and I am passing chartData array to pie(title,chartData) function as second parameter.
Now chartData array is placing in data: [ chartData ] but it not working.
But when I add manually with key then It work data: [ chartData[0],chartData[1], ].
But I don't want to mention it manually with key. I want to arry work automatically like data: [ chartData ] What I have to do?

function createChart(chart) {
if ( chart == 'pie' ) {     

    var title = $("#chart-title").val();        

    /***************** Data Elements ****************/
    var totalElements = $("#addMoreRowNo").val();

    var chartData = new Array();
    for(var j = 1; j <= totalElements; j++)
    {                       
        var key = $("#chart-pie-text_"+j).val();
        var value = $("#chart-pie-percentage_"+j).val();
        var data = [key, parseFloat(value)];
        chartData[j-1] = data;
    }       
    /***************** Data Elements ****************/

    pie(title,chartData);
  }
}


function pie(title,chartData) {
var chart;

chart = new Highcharts.Chart({
    chart: {
        renderTo: 'container',
        plotBackgroundColor: null,
        plotBorderWidth: null,
        plotShadow: false
    },
    title: {
        text: title
    },
    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: 'Browser share',
        data: [

           chartData      
               /*chartData[0],
               chartData[1],*/

            //['Active Postings (13)', 20.00],

        ]
    }]
});    
 }

1 Answer 1

1

I'm pretty sure your problem can be solved by replacing

data: [
  chartData
]

with

data : chartData

The way you're writing it, you're defining data as an array containing chartData, which itself is an array. The way you indicate you're testing it, though, is to get the items out of chartData and put each item into data, which results in a different structure.

Sign up to request clarification or add additional context in comments.

1 Comment

"This question shows research effort; it is useful and clear" -- I'm happy to help out, but your question is very difficult to understand, contains a huge amount of extraneous code, and shows a lack of effort on your part to simply debug through your own code and find a simple sintax error. I'm glad I could help you out, but I don't think this question is likely to be useful to a lot of other people.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.