示例#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
 /**
  * Used to create a stacked bar-chart.
  * For each set of bar-values you can call this method once.
  * A sample-code could be:
  *  $objGraph = new class_graph();
  *  $objGraph->setStrXAxisTitle("x-axis");
  *  $objGraph->setStrYAxisTitle("y-axis");
  *  $objGraph->setStrGraphTitle("Test Graph");
  *
  *
  *  //simple array
  *      $objGraph->addStackedBarChartSet(array(1,2,4,5) "serie 1");
  *      $objGraph->addStackedBarChartSet(array(1,2,4,5) "serie 2");
  *
  * //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->addStackedBarChartSet(array($objDataPoint1, $objDataPoint2, $objDataPoint3, $objDataPoint4) "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 string $strLegend
  *
  * @throws class_exception
  * @return void
  */
 public function addStackedBarChartSet($arrValues, $strLegend)
 {
     $arrDataPoints = class_graph_commons::convertArrValuesToDataPointArray($arrValues);
     if ($this->intCurrentGraphMode > 0) {
         //only allow this method to be called again if in stackedbar-mode
         if ($this->intCurrentGraphMode != $this->GRAPH_TYPE_STACKEDBAR) {
             throw new class_exception("Chart already initialized", class_exception::$level_ERROR);
         }
     }
     //add max value from each set to max value
     $intMax = 0;
     $intMin = 0;
     foreach ($arrDataPoints as $objDataPoint) {
         $floatValue = $objDataPoint->getFloatValue();
         if ($floatValue > $intMax) {
             $intMax = $floatValue;
         }
         if ($floatValue < $intMin) {
             $intMin = $floatValue;
         }
     }
     $this->intMaxValue += $intMax;
     $this->intMinValue -= $intMin;
     $this->intCurrentGraphMode = $this->GRAPH_TYPE_STACKEDBAR;
     $this->addBarChartSet(class_graph_commons::getDataPointFloatValues($arrDataPoints), $strLegend);
     $this->intCurrentGraphMode = $this->GRAPH_TYPE_STACKEDBAR;
 }