highcharts,json数据:行和列 [英] highcharts, json data: line and column

查看:235
本文介绍了highcharts,json数据:行和列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能是真正的基本问题:

May be really basic question:

我使用两个系列的highcharts,一个用line表示,另一个用column表示,数据使用json加载,问题是如何告诉highcharts一个系列应该用线表示,另一个用列类型表示,例如 this

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

我)在highcharts的json模式的系列选项只有这样:

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,
    .......

我缺少某些东西?

从db中检索数据的php代码:

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);

输出如下:

    [{"name":"MaxPax","data":[40,19,40,21]},{"name":"Overhead","data":                 [21990,22365,21987,22369,22558,22987,23521,23003,22756,23112,22987,22897]}]


推荐答案

您需要在JSON中定义此参数,或在接收后解析您的json,并设置此副本,然后在Highcharts中使用。

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

编辑:
您可以替换此行

You can replace this lines

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

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

在下一个系列中类似。
第二个解决方案是获取json之后的push类型:

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);
});

这篇关于highcharts,json数据:行和列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆