0

May be really basic question:

I'm playing with highcharts with two series, one represented with line and other with column, data is loaded using json, the problem is in how to tell highcharts one serie should be represented with line and the other with column type, like this

The problem (for me) comes when Series options in json mode of highcharts are only like this:

         }, 
            series: json
        });

whilst in "normal mode" you can set for example:

    series: [{
**type: 'column',**
    name: 'Name',
    data: [],
},{
type: 'spline',
    name: 'Max Pax',
    data: [],
draggableY: true,
dragMinY: 0,
    dragMaxY: 200,
    .......

Am I missing something?

php code that retrives data from db:

    $con = mysql_connect("localhost", "*******","*******");

if (!$con) {
die('Could not connect: ' . mysql_error());
}

mysql_select_db("wordpress_8", $con);

$sth = mysql_query("SELECT * FROM wp_maxpax_A where fecha='12/11/2013' ");
$rows = array();
$rows['name'] = 'MaxPax';
while($r = mysql_fetch_array($sth)) {
$rows['data'][] = $r['a1300'];
$rows['data'][] = $r['a1315'];
$rows['data'][] = $r['a1330'];
$rows['data'][] = $r['a1345'];

}

$sth = mysql_query("SELECT overhead FROM projections_sample");
$rows1 = array();
$rows1['name'] = 'Overhead';
while($rr = mysql_fetch_assoc($sth)) {
$rows1['data'][] = $rr['overhead'];
}

$result = array();
array_push($result,$rows);
array_push($result,$rows1);


print json_encode($result, JSON_NUMERIC_CHECK);

Output looks like:

    [{"name":"MaxPax","data":[40,19,40,21]},{"name":"Overhead","data":                 [21990,22365,21987,22369,22558,22987,23521,23003,22756,23112,22987,22897]}]
1
  • Can you show us the server side code you are using to return the json data ? Commented Jan 13, 2014 at 15:49

1 Answer 1

2

You need to define this parameter in JSON, or parse your json after receive, and set this paraemter, then use in Highcharts.

EDIT: You can replace this lines

$sth = mysql_query("SELECT * FROM wp_maxpax_A where fecha='12/11/2013' ");
$rows = array();
$rows['name'] = 'MaxPax';

with

$sth = mysql_query("SELECT * FROM wp_maxpax_A where fecha='12/11/2013' ");
$rows = array();
$rows['name'] = 'MaxPax';
$rows['type'] = 'line';

Similar in next series. Second solution is push type after getting json like:

$getJSON('path/to/json',function(data){


 data[0].type='column';
 data[1].type='line';

 var options = {
    // your options
    series: data
 };

 $('#container').highcharts(options);
});
Sign up to request clarification or add additional context in comments.

6 Comments

So if I'm using a php file that create and fetch query to db, is inside this file where I should set this options? if yes, any tutorial or something to start from? (I dont know how to do this via json)
You need to set it in php (one way) or get json in javascript (getJSON()) function, and parse json. I mean use loops and add your parameter. Will be great if your will attach your json.
In case when we have no access to database, how we can got JSON form your code? Please attach json which is returned in this line: print json_encode($result, JSON_NUMERIC_CHECK);
added to the main question, output looks like: [{"name":"MaxPax","data":[40,19,40,21]},{"name":"Overhead","data":[21990,22365,21987,22369,22558,22987,23521,23003,22756,23112,22987,22897]}]
so I can add all config params in json file using the format you shared?
|

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.