基于GD库和JPgraph库

说明:对于具体的Jpgraph类库的用法,请参照官网的文档:http://jpgraph.net/download/manuals/classref/index.html

对于下面涉及到的代码,里面的JPgraph类文件可能路径不一样,我是按照我自己文件存放的路径引入的。你们可自行更改

1、使用柱形图统计月销量额

<?php
    /*
        具体的Jpgraph类库的用法,请参照官网的文档:
        http://jpgraph.net/download/manuals/classref/index.html
    */
    /*****************************使用柱形图统计月销量额**************************/
    include("D:/PHP_Config/jpgraph-3.5.0b1/src/jpgraph.php");
    include("D:/PHP_Config/jpgraph-3.5.0b1/src/jpgraph_bar.php"); //引用柱形图对象所在的文件
    $datay = array(160,180,203,289,405,488,489,408,299,166,187,105); //定义数组
    $graph = new Graph(600,300,"auto"); //创建画布 --要JPgraph库的支持
    $graph->SetScale("textlin");
    $graph->yaxis->scale->SetGrace(20);
    $graph->SetShadow();  //创建画布阴影
    //设置统计图所在画布的位置,左边距40、右边距30、上边距30、下边距40,单位为像素
    $graph->img->SetMargin(40,30,30,40);
    
    $bplot = new BarPlot($datay);  //创建一个矩形的对象
    $bplot->SetFillColor('orange');   //设置柱形图的颜色
    $bplot->value->Show();   //设置显示数字
    $bplot->value->SetFormat('%d');   //在柱形图中显示格式化的图书销量
    
    $graph->Add($bplot);  //将矩形图添加到图像中
    $graph->SetMarginColor("lightblue");  //设置画布背景色为浅蓝色
    $graph->title->Set("<<PHP for Introduction 2009>> Annual sales statistics");  //创建标题
    //设置X轴坐标文字
    $a=array("1 月","2 月","3 月","4 月","5 月","6 月","7 月","8 月","9 月","10 月","11 月","12 月");
    $graph->xaxis->SetTickLabels($a);   //设置X轴
    $graph->title->SetFont(FF_SIMSUN);  //设置标题字体
    $graph->xaxis->SetFont(FF_SIMSUN);  //设置X轴的字体
    $graph->Stroke();  //输出图像
?>
View Code

相关文章:

  • 2021-08-01
  • 2021-05-11
  • 2022-12-23
  • 2021-12-12
  • 2021-08-31
  • 2021-09-18
  • 2021-12-27
  • 2021-11-12
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-19
  • 2022-12-23
  • 2022-01-16
  • 2021-04-18
相关资源
相似解决方案