PHP—Open flash chart显示图表、修改坐标值、旋转X轴值、读取数据库并显示
![此博文包含图片](https://i-blog.csdnimg.cn/blog_migrate/a4c26d1e5885305701be709a3d33442f.gif)
分类: 网站前端 |
PHP—Open flash chart显示图表、修改坐标值、旋转X轴值、 调用数据库并显示、X轴显示中文!
1:如何使用Open Flash chart插件显示图表
①:首先下载Open Flash chart插件:下载官网地址:http://sourceforge.net/projects/openflashchart/files/;
②:复制以下文件夹到你的网站根目录下:data-files、js、js-ofc-library、open-flash-chart、php5-ofc-library、php-ofc-library、复制open-flash-chart-2-Lug-Wyrm-Charmer\dot-net-library\written-by-xiao-yifang\ofcWebTest\open-flash-chart-SimplifiedChinese.swf;
③:新建jason数据文件,(放在网站根目录下,此代码包括,从数据库中读取数据,显示图表)
数据库设计如下:
header("Content-type=text/html; chart-set=utf-8");
include 'conn.php';
$sqlc = "select chit from count";
$sqlc_1 = mysql_query($sqlc);
while ($sqlc_2 = mysql_fetch_array($sqlc_1)) {
}
require_once('php-ofc-library/open-flash-chart.php');
srand((double) microtime() * 1000000);
$max = 20;
$tmp = array();
for ($i = 0; $i < 9; $i++) {
}
$title = new title("统计图");
$bar = new line();
$bar->set_key("2006", 10);
$bar->set_values(array(1, 5, 3, 0, 5, 6, 10, 8, 9));
//$bar->text='总值趋势';//和$bar->set_key("2006",10);一样
$bar2 = new bar_glass();
$bar2->set_values($newsarray);
$bar2->set_colour("#fe5c03");
$bar2->set_alpha(0.5);
$bar2->set_key("2007", 12);
$bar->set_on_show(new bar_on_show('drop', .5, 0));
$chart = new open_flash_chart();
$chart->set_bg_colour("#ffffff");
$chart->set_title($title);
$y = new y_axis();
$y->set_colour('#d7e4a3');
//$y->set_stroke(10);//y线宽度;
$y->set_range(0, 15, 3);
$chart->set_y_axis($y);
$xdata =array('一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月');
$x = new x_axis();
$x->set_colour('#d7e4a3'); //设置X轴线的颜色
$x->set_tick_height(5); //设置X轴上数据与线之间的距离,坐标值
//$x->set_grid_colour('#fff000');//网格颜色
//$y->set_grid_colour('#fff000');
$x_labels = new x_axis_labels();
$x_labels->set_labels($xdata);
$x_labels->rotate(-30);//X轴旋转
$x_labels->set_steps(1); //设置X轴标签数据的间隔
//$x_labels->set_vertical(); //设置X轴标签为垂直
$x->set_labels($x_labels);
//$x->set_range(0,10,1);
$chart->set_x_axis($x);
//$chart->set_y_legend('Chart report',12,'#736AFF');
$chart->add_element($bar);
$chart->add_element($bar2);
echo $chart->toPrettyString();
④:在根目录下新建一文件名为:chart_test.php
代码如下:
<html>
<head>
<script type="text/javascript" src="js/swfobject.js"></script>
<script type="text/javascript">
swfobject.embedSWF(
);
</script>
</head>
<body>
<div id="my_chart"></div>
</body>
</html>
注:让X轴显示中文的操作步骤:
open-flash-chart.swf显示英文,设置中文不显示
open-flash-chart-2-Lug-Wyrm-Charmer\dot-net-library\written-by-xiao-yifang\ofcWebTest\open-flash-chart-SimplifiedChinese.swf显示中文