一 代码
<?php require_once 'src/jpgraph.php'; //导入Jpgraph类库 require_once 'src/jpgraph_line.php'; //导入Jpgraph类库的柱状图功能 $data1 = array(89, 78, 99, 65, 92, 85 ,85 ,55, 64, 79, 85, 98); //设置统计数据 $data2 = array(68, 70, 69, 80, 50, 60 ,75 ,65, 64, 80, 75, 65); //设置统计数据 $graph = new Graph(1000, 400); $graph->SetScale("textlin"); $graph->setY2Scale("lin"); $graph->SetShadow(); $graph->img->SetMargin(50, 60, 50, 20); $graph->title->Set("图书销售走势表"); $lineplot1 = new LinePlot($data1); $lineplot2 = new LinePlot($data2); $graph->Add($lineplot1); $graph->AddY2($lineplot2); $graph->xaxis->title->Set("月份"); $graph->yaxis->title->Set("book A销售金额(万元)"); $graph->y2axis->title->Set("book B销售金额(万元)"); $graph->title->SetFont(FF_SIMSUN, FS_BOLD); $graph->yaxis->title->SetFont(FF_SIMSUN, FS_BOLD); $graph->y2axis->title->SetFont(FF_SIMSUN, FS_BOLD); $graph->xaxis->title->SetFont(FF_SIMSUN, FS_BOLD); $lineplot1->SetColor('red'); $lineplot2->SetColor('blue'); $lineplot1->SetLegend('book A'); $lineplot2->SetLegend('book B'); $graph->legend->SetLayout(LEGEND_HOR); $graph->legend->Pos(0.4, 0.95, 'center', 'bottom'); $graph->Stroke();
二 运行结果