我正在使用带有codeigniter的高图。我从blueflame得到了一些参考。这是我的代码,结果为空。 当我要跑步时,它显示空白结果。我必须改变才能正确得到结果。
控制器:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Chart extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->database();
$this->load->model('Data');
}
public function index()
{
//echo "adsf";exit;
$this->load->view('chart_view');
}
public function data()
{
$result = $this->Data->get_data();
$category = array();
$category['name'] = 'Category';
$series1 = array();
$series1['id'] = 'ebay_token';
$series2 = array();
$series2['id'] = 'development_id';
$series3 = array();
$series3['id'] = 'application_id';
$series4 = array();
$series4['id'] = 'certification_id';
foreach ($result as $row)
{
$category['result'][] = $row->ebay_token;
$category['result'][] = $row->development_id;
$category['result'][] = $row->application_id;
$category['result'][] = $row->certification_id;
}
$final = array();
array_push($final,$category);
array_push($final,$series1);
array_push($final,$series2);
array_push($final,$series3);
array_push($final,$series4);
print json_encode($final, JSON_NUMERIC_CHECK);
}
}
型号:
<?php
class Data extends CI_Model
{
public function __construct()
{
parent::__construct();
}
public function get_data()
{
$this->db->select('ebay_token,application_id,development_id,certification_id');
$this->db->from('ebay_configuration');
$query = $this->db->get();
return $query->result();
}
}
查看:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
var options =
{
chart:
{
renderTo: 'chartcon',
type: 'line',
marginRight: 130,
marginBottom: 25
},
title:
{
text: 'Project Requests',
x: -20 //center
},
subtitle:
{
text: '',
x: -20
},
xAxis:
{
categories: []
},
yAxis:
{
title:
{
text: 'Requests'
},
plotLines:
[{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip:
{
formatter: function()
{
return '<b>'+ this.series.id +'</b>'+
this.x +': '+ this.y;
}
},
legend:
{
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: []
}
$.getJSON("result", function(json)
{
options.xAxis.categories = json[0]['result'];
options.series[0] = json[1];
options.series[1] = json[2];
options.series[2] = json[3];
options.series[3] = json[4];
chart = new Highcharts.Chart(options);
});
});
</script>
<script type="text/javascript" src="http://code.highcharts.com/highcharts.js"></script>
<script type="text/javascript" src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="chartcon" style="min-width: 400px; height: 400px; margin: 0 auto;"></div>