예제 #1
0
 private function strCreateJSDataArray()
 {
     $arrData = array();
     if ($this->containsChartType(class_graph_jqplot_charttype::PIE) && $this->arrXAxisTickLabels != null) {
         foreach ($this->arrSeriesData as $keySeries => $objSeriesData) {
             $arrSeries = array();
             $arrDataPointsTemp = $objSeriesData->getArrDataPoints();
             foreach ($this->arrXAxisTickLabels as $keyLabel => $strLabelData) {
                 $arrSeries[] = array($strLabelData, $arrDataPointsTemp[$keyLabel]->getFloatValue());
             }
             $arrData[] = $arrSeries;
         }
     } else {
         foreach ($this->arrSeriesData as $objSeriesData) {
             $arrData[] = class_graph_commons::getDataPointFloatValues($objSeriesData->getArrDataPoints());
         }
     }
     return json_encode($arrData);
 }
예제 #2
0
 /**
  * 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);
 }
예제 #3
0
 /**
  * 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);
 }