private function _renderPlotBar($groupID, $dimensions = '2d') { $rotation = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotDirection(); // Rotate for bar rather than column chart if ($groupID == 0 && $rotation == 'bar') { $this->_graph->Set90AndMargin(); } $grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping(); $labelCount = count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount()); if ($labelCount > 0) { $datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues(); $datasetLabels = $this->_formatDataSetLabels($groupID, $datasetLabels, $labelCount, $rotation); // Rotate for bar rather than column chart if ($rotation == 'bar') { $datasetLabels = array_reverse($datasetLabels); $this->_graph->yaxis->SetPos('max'); $this->_graph->yaxis->SetLabelAlign('center', 'top'); $this->_graph->yaxis->SetLabelSide(SIDE_RIGHT); } $this->_graph->xaxis->SetTickLabels($datasetLabels); } $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount(); $seriesPlots = array(); if ($grouping == 'percentStacked') { $sumValues = $this->_percentageSumCalculation($groupID, $seriesCount); } // Loop through each data series in turn for ($j = 0; $j < $seriesCount; ++$j) { $dataValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($j)->getDataValues(); if ($grouping == 'percentStacked') { $dataValues = $this->_percentageAdjustValues($dataValues, $sumValues); } // Fill in any missing values in the $dataValues array $testCurrentIndex = 0; foreach ($dataValues as $k => $dataValue) { while ($k != $testCurrentIndex) { $dataValues[$testCurrentIndex] = null; ++$testCurrentIndex; } ++$testCurrentIndex; } // Reverse the $dataValues order for bar rather than column chart if ($rotation == 'bar') { $dataValues = array_reverse($dataValues); } $seriesPlot = new BarPlot($dataValues); $seriesPlot->setBackgroundColor('black'); $seriesPlot->SetFillColor(self::$_colourSet[self::$_plotColour++]); if ($dimensions == '3d') { $seriesPlot->SetShadow(); } if (!$this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($j)) { $dataLabel = ''; } else { $dataLabel = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($j)->getDataValue(); } $seriesPlot->SetLegend($dataLabel); $seriesPlots[] = $seriesPlot; } // Reverse the plot order for bar rather than column chart if ($rotation == 'bar' && !($grouping == 'percentStacked')) { $seriesPlots = array_reverse($seriesPlots); } if ($grouping == 'clustered') { $groupPlot = new GroupBarPlot($seriesPlots); } elseif ($grouping == 'standard') { $groupPlot = new GroupBarPlot($seriesPlots); } else { $groupPlot = new AccBarPlot($seriesPlots); if ($dimensions == '3d') { $groupPlot->SetShadow(); } } $this->_graph->Add($groupPlot); }
function dis_chart_bar($chart) { $values = $chart["values"]; $labels = $chart["labels"]; $title = $chart["title"]; $xlabels = $chart["xlabels"]; $graph = new Graph(600, 250); $graph->setAntiAliasing(TRUE); // Chart infos : colors, size, shaow $plot = new BarPlot($values, 1, 1); $plot->setBarColor(new Color(42, 71, 180)); $plot->setBackgroundColor(new Color(240, 240, 240)); $plot->setBarSize(0.6); $plot->setSpace(3, 3, NULL, NULL); $plot->barShadow->setSize(2); $plot->barShadow->smooth(TRUE); // Labels infos $label = new Label($labels); $label->setFont(new Tuffy(8)); $label->setAlign(NULL, LABEL_TOP); $plot->label = $label; // X axis Labels infos $xlabel = new Label($xlabels); $plot->xAxis->setlabelText($xlabels); // Title infos if ($title != "") { $graph->title->set("$title"); } $graph->add($plot); $graph->draw(); }