/** * Creates a new pie-chart. Pass the values as the first param. If * you want to use a legend and / or Colors use the second and third param. * Make sure the array have the same number of elements, ohterwise they won't * be uses. * A sample-code could be: * $objChart = new class_graph(); * $objChart->setStrGraphTitle("Test Pie Chart"); * * //simple array * $objChart->createPieChart(array(2,6,7,3), array("val 1", "val 2", "val 3", "val 4")); * * //datapoints array * $objDataPoint1 = new class_graph_datapoint(1); * $objDataPoint2 = new class_graph_datapoint(2); * $objDataPoint3 = new class_graph_datapoint(4); * $objDataPoint4 = new class_graph_datapoint(5); * * //set action handler example * $objDataPoint1->setObjActionHandler("<javascript code here>"); * $objDataPoint1->getObjActionHandlerValue("<value_object> e.g. some json"); * * $objGraph->createPieChart(array($objDataPoint1, $objDataPoint2, $objDataPoint3, $objDataPoint4) , array("val 1", "val 2", "val 3", "val 4"), "serie 1"); * * * @param array $arrValues - an array with simple values or an array of data points (class_graph_datapoint). * The advantage of a data points are that action handlers can be defined for each data point which will be executed when clicking on the data point in the chart. * @param array $arrLegends * * @throws class_exception */ public function createPieChart($arrValues, $arrLegends) { $arrDataPoints = class_graph_commons::convertArrValuesToDataPointArray($arrValues); if ($this->containsChartType(class_graph_jqplot_charttype::LINE) || $this->containsChartType(class_graph_jqplot_charttype::BAR) || $this->containsChartType(class_graph_jqplot_charttype::STACKEDBAR)) { throw new class_exception("Chart already contains either a line, bar or stacked bar chart. Combinations of pie charts with other charts are not allowed", class_exception::$level_ERROR); } if ($this->containsChartType(class_graph_jqplot_charttype::PIE)) { throw new class_exception("Chart already contains either a pie chart.Only one pie chart per chart is allowed", class_exception::$level_ERROR); } $objSeriesData = new class_graph_jqplot_seriesdata(class_graph_jqplot_charttype::PIE, count($this->arrSeriesData), $this->arrOptions); $objSeriesData->setArrDataPoints($arrDataPoints); $this->arrXAxisTickLabels = $arrLegends; //set to this array, as the data array is built up similar $this->arrSeriesData[] = $objSeriesData; }
/** * Creates a new pie-chart. Pass the values as the first param. If * you want to use a legend and / or Colors use the second and third param. * Make sure the array have the same number of elements, ohterwise they won't * be uses. * A sample-code could be: * $objChart = new class_graph(); * $objChart->setStrGraphTitle("Test Pie Chart"); * * //simple array * $objChart->createPieChart(array(2,6,7,3), array("val 1", "val 2", "val 3", "val 4")); * * //datapoints array * $objDataPoint1 = new class_graph_datapoint(1); * $objDataPoint2 = new class_graph_datapoint(2); * $objDataPoint3 = new class_graph_datapoint(4); * $objDataPoint4 = new class_graph_datapoint(5); * * //set action handler example * $objDataPoint1->setObjActionHandler("<javascript code here>"); * $objDataPoint1->getObjActionHandlerValue("<value_object> e.g. some json"); * * $objGraph->createPieChart(array($objDataPoint1, $objDataPoint2, $objDataPoint3, $objDataPoint4) , array("val 1", "val 2", "val 3", "val 4"), "serie 1"); * * * @param array $arrValues - an array with simple values or an array of data points (class_graph_datapoint). * The advantage of a data points are that action handlers can be defined for each data point which will be executed when clicking on the data point in the chart. * @param array $arrLegends * * @throws class_exception * @return void */ public function createPieChart($arrValues, $arrLegends) { $arrDataPoints = class_graph_commons::convertArrValuesToDataPointArray($arrValues); if ($this->intCurrentGraphMode > 0) { throw new class_exception("Chart already initialized", class_exception::$level_ERROR); } $this->intCurrentGraphMode = $this->GRAPH_TYPE_PIE; $strSerieName = generateSystemid(); $this->objDataset->AddPoint(class_graph_commons::getDataPointFloatValues($arrDataPoints), $strSerieName); $this->objDataset->AddSerie($strSerieName); $strSerieName = generateSystemid(); foreach ($arrLegends as &$strValue) { $strValue = $this->stripLegend($strValue); } $this->objDataset->AddPoint($arrLegends, $strSerieName); $this->objDataset->AddSerie($strSerieName); $this->objDataset->SetAbsciseLabelSerie($strSerieName); }
/** * Creates a new pie-chart. Pass the values as the first param. If * you want to use a legend and / or Colors use the second and third param. * Make sure the array have the same number of elements, ohterwise they won't * be uses. * A sample-code could be: * $objChart = new class_graph(); * $objChart->setStrGraphTitle("Test Pie Chart"); * * //simple array * $objChart->createPieChart(array(2,6,7,3), array("val 1", "val 2", "val 3", "val 4")); * * //datapoints array * $objDataPoint1 = new class_graph_datapoint(1); * $objDataPoint2 = new class_graph_datapoint(2); * $objDataPoint3 = new class_graph_datapoint(4); * $objDataPoint4 = new class_graph_datapoint(5); * * //set action handler example * $objDataPoint1->setObjActionHandler("<javascript code here>"); * $objDataPoint1->getObjActionHandlerValue("<value_object> e.g. some json"); * * $objGraph->createPieChart(array($objDataPoint1, $objDataPoint2, $objDataPoint3, $objDataPoint4) , array("val 1", "val 2", "val 3", "val 4"), "serie 1"); * * * @param array $arrValues - an array with simple values or an array of data points (class_graph_datapoint). * The advantage of a data points are that action handlers can be defined for each data point which will be executed when clicking on the data point in the chart. * @param array $arrLegends * * @throws class_exception * @return void */ public function createPieChart($arrValues, $arrLegends) { $arrDataPoints = class_graph_commons::convertArrValuesToDataPointArray($arrValues); if ($this->intCurrentGraphMode > 0) { throw new class_exception("Chart already initialized", class_exception::$level_ERROR); } $this->intCurrentGraphMode = $this->GRAPH_TYPE_PIE; $arrEntries = array(); foreach ($arrDataPoints as $intKey => $objDataPoint) { $floatValue = $objDataPoint->getFloatValue(); $arrEntries[$arrLegends[$intKey]] = $floatValue; } $objData = new ezcGraphArrayDataSet($arrEntries); $objData->highlight = true; $this->arrDataSets[generateSystemid() . ""] = array("data" => $objData); }