Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-01-09
2
Medium Priority
?
2,267 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Suggested Courses

926 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