Solved

How to take values from a json array and use in highchart

Posted on 2013-01-09
2
2,106 Views
Last Modified: 2013-01-09
Hi,
I'm painfully new at this so my explanation may not be the best.

I have a number of div's being populated as a result of a call to mysql database. I am trying to use a few of the values in the return json to populate a highcharts column as well.

I can't figure out how to get at the returned values that I'm using for the div's so I can populate my chart as well with some of them.

Code example (simplified so you can see the issue easier).

How to get the data.phonetotal, data.uniquetotal and data.texttotal into the first values of my chart as the example??

$(document).ready( function () {

 $.get("assets/db/contest_history_detail.php?contest_id=" + $("select[name='contests']").val(),
   function(data){
	$('#stat1').html( data.phonetotal );
	$('#stat2').html( data.uniquetotal );
	$('#stat3').html( data.texttotal );
   }, "json");
   
 var chart;
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'bars',
                 backgroundColor: 'rgba(255,255,255,0)',
                type: 'column'
            },
             series: [{
                name: 'This Contest',
                data: [?, ?, ?]
    
            }, {
                name: 'Last Contest',
                data: [10, 4, 3]
              
            }]
        });
    });

Open in new window


Any help would be very much appreciated.

In case it helps, this is what is being echo'd back to my page when the mysql request is made:
echo json_encode(array(
"phonetotal"=>$phonetotal,
"uniquetotal"=>$uniquetotal,
"texttotal"=>$texttotal));

Open in new window

0
Comment
Question by:tjyoung
2 Comments
 
LVL 12

Accepted Solution

by:
sivagnanam chandrakanth earned 500 total points
ID: 38758554
So the problem is getting the returned array into hightchart..If yes, below is the solution

move your highchart code into function(data){ ......} and pass data like below

series: [{
                name: 'This Contest',
                data: data
   
            },
0
 
LVL 1

Author Closing Comment

by:tjyoung
ID: 38759440
Thanks simple as you described. Much appreciated
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now