2

Hi I am using highchart API for generating graph in loop

 for(i=1;i<10;i++)
                {

            xseries = "{'INCOPAV','B&M','SGS-ETSA'}";
            yseries = "[{name: 'Generados',data: [49.9, 71.5, 106.4]}, {name: 'Cerrados',data: [83.6, 78.8, 98.5]}]";

            generateAllGraph('graph_container'+i,'abcd'+i,xseries,yseries);

                }



function generateAllGraph(container,graphTitle,XaxesSeries,YaxesSeries)
{

                     $('#'+container+'').highcharts({
                                chart: {
                           renderTo: container,
                           type: 'column'
                       },
                       title: {
                           text: graphTitle
                       },
                       subtitle: {
                           text: ''
                       },
                       legend: {

                           itemStyle: {
                               fontSize: "10px"

                           }
                       },
                       xAxis: {
                           categories:  [XaxesSeries]

                       },
                   yAxis: {
                       min: 0,
                       title: {
                           text: 'Registros'
                       }
                   },

               tooltip: {
                   formatter: function() {
                       return ''+
                           this.x +': '+ this.y +' Registros';
                   }
               },
               plotOptions: {
                   column: {
                       pointPadding: 0.2,
                       borderWidth: 0
                   }
               },
               series: YaxesSeries
           });
}

but it is not taking X and Y axes as per argument

I think there is something wrong in passing X-axes and y-axes variable I tried it with using jQuery.parseJSON( ) but not getting result

and giving output like this

please help me

enter image description here

2 Answers 2

3

First of all as SteveP said, xseries is not a proper array declaration.

Once you sort that out, you need to get rid of the double quotes around the xseries/yseries. What you need to do is:

var json1 = jQuery.parseJSON(xseries); var json2 = jQuery.parseJSON(yseries);

and pass these variables around.

Hope that helps

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

1 Comment

I was wrong in JSON format otherwise I used same code before post question and again Its working ....just I need to check JSON format over jsonlint.com site
3

You are passing the series as strings, not as objects. Also, the xseries is not a valid array declaraton. Try:

xseries = ['INCOPAV','B&M','SGS-ETSA'];
yseries = [
       {name: 'Generados',
        data: [49.9, 71.5, 106.4]
       },
       {
        name: 'Cerrados',
        data: [83.6, 78.8, 98.5]
       }
      ];

(Note, no double quotes around it.

Comments

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.