从数据库获取数据
我已使用以下视图将 Fusion 图表实现到 Codeigniter 框架中。我正在使用视图中提供的数据创建折线图,但是我想从相同的结构化数据库表中检索此数据。
有办法做吗?如果有人可以帮助我,我将非常感激。
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<?php
class Chart extends CI_Controller {
function __construct()
{
session_start();
parent::__construct();
if ( !isset($_SESSION['username']) ) {
redirect('admin');
}
}
public function index() {
$this->load->helper(array('url','fusioncharts')) ;
$graph_swfFile = base_url().'public/flash/Line.swf' ;
$graph_caption = 'Results' ;
$graph_numberPrefix = '€ ' ;
$graph_title = 'Results' ;
$graph_width = 600 ;
$graph_height = 250 ;
// Store Name of Products
$arrData[0][1] = "Novomatic";
$arrData[1][1] = "Atronic";
$arrData[2][1] = "Williams";
$arrData[3][1] = "Roulettes";
$arrData[4][1] = "IGT";
$arrData[5][1] = "Interblock";
//Store sales data
$arrData[0][2] = 567500;
$arrData[1][2] = 815300;
$arrData[2][2] = 556800;
$arrData[3][2] = 734500;
$arrData[4][2] = 676800;
$arrData[5][2] = 648500;
$strXML = "<graph caption='".$graph_caption."' numberPrefix='".$graph_numberPrefix."' formatNumberScale='0' decimalPrecision='0'>";
//Convert data to XML and append
foreach ($arrData as $arSubData) {
$strXML .= "<set name='" . $arSubData[1] . "' value='" . $arSubData[2] . "' color='".getFCColor()."' />";
}
//Close <chart> element
$strXML .= "</graph>";
$data['graph'] = renderChart($graph_swfFile, $graph_title, $strXML, "div" , $graph_width, $graph_height);
//$this->load->view('chart_view',$data) ;
$this->template->load('includes/template', 'chart_view' ,$data);
}
}
I have implemented Fusion charts into Codeigniter
framework with following view. I am creating line chart with provided data in view but, I would like to retrieve this data from same structured database table.
Is there anyway to do it? I will be really appreciated if someone can help me.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<?php
class Chart extends CI_Controller {
function __construct()
{
session_start();
parent::__construct();
if ( !isset($_SESSION['username']) ) {
redirect('admin');
}
}
public function index() {
$this->load->helper(array('url','fusioncharts')) ;
$graph_swfFile = base_url().'public/flash/Line.swf' ;
$graph_caption = 'Results' ;
$graph_numberPrefix = '€ ' ;
$graph_title = 'Results' ;
$graph_width = 600 ;
$graph_height = 250 ;
// Store Name of Products
$arrData[0][1] = "Novomatic";
$arrData[1][1] = "Atronic";
$arrData[2][1] = "Williams";
$arrData[3][1] = "Roulettes";
$arrData[4][1] = "IGT";
$arrData[5][1] = "Interblock";
//Store sales data
$arrData[0][2] = 567500;
$arrData[1][2] = 815300;
$arrData[2][2] = 556800;
$arrData[3][2] = 734500;
$arrData[4][2] = 676800;
$arrData[5][2] = 648500;
$strXML = "<graph caption='".$graph_caption."' numberPrefix='".$graph_numberPrefix."' formatNumberScale='0' decimalPrecision='0'>";
//Convert data to XML and append
foreach ($arrData as $arSubData) {
$strXML .= "<set name='" . $arSubData[1] . "' value='" . $arSubData[2] . "' color='".getFCColor()."' />";
}
//Close <chart> element
$strXML .= "</graph>";
$data['graph'] = renderChart($graph_swfFile, $graph_title, $strXML, "div" , $graph_width, $graph_height);
//$this->load->view('chart_view',$data) ;
$this->template->load('includes/template', 'chart_view' ,$data);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您只需要根据表中的数据而不是现有代码中的数组构建 XML。
示例代码可以来自:
这是对同一问题的讨论:
http://codeigniter。 com/forums/viewthread/136095/#671946
但是,您还可以使用 FusionCharts 提供的更好的数据生成器和图表生成器 PHP 类帕克克。
详细阅读请参阅 FusionCharts 文档:
http://www.fusioncharts.com/docs/ > ; Web 开发人员指南 > FusionCharts PHP 类
或
http://www.fusioncharts.com/docs/ > Web 开发人员指南 >使用 PHP 类
Primarily, you would just need to build the XML from the data from your table instead of the array in your existing code.
Sample code can be derived from :
Here is a discussion on the same issue:
http://codeigniter.com/forums/viewthread/136095/#671946
However, you can also use a better data builder and chart generator PHP class provided with FusionCharts pakck.
For detailed reading please refer to FusionCharts Documehtation:
http://www.fusioncharts.com/docs/ > Guide For Web Developers > FusionCharts PHP Class
or
http://www.fusioncharts.com/docs/ > Guide For Web Developers > Using PHP Class