Solved

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

Posted on 2013-01-09
2
2,139 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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)

820 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