Solved

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

Posted on 2013-01-09
2
2,083 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
Comment Utility
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
Comment Utility
Thanks simple as you described. Much appreciated
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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)
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…

743 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

16 Experts available now in Live!

Get 1:1 Help Now