/** * Gera um gráfico de linha * @param array $dados Array no formato array('Label' => array(pontos)) * @param string $tipo linha ou barra */ function grafico($dados, $tipo = 'linha') { require_once 'exemplos/graficos/pChart/class/pDraw.class.php'; require_once 'exemplos/graficos/pChart/class/pImage.class.php'; require_once 'exemplos/graficos/pChart/class/pData.class.php'; // precisamos ter dados para montar os gráficos $DataSet = new pData(); // Adicionando os pontos de um gráfico de linha // horas de trabalho na semana foreach ($dados as $label => $pontos) { $DataSet->addPoints($pontos, $label); } $DataSet->setAxisName(0, 'Horas'); // unidade $DataSet->setAxisUnit(0, 'h'); $settings = array("R" => 229, "G" => 11, "B" => 11, "Alpha" => 80); $DataSet->setPalette("Joao", $settings); // Labels $DataSet->addPoints(array('Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado'), 'Dias'); $DataSet->setSerieDescription('Dias', 'Dias da Semana'); $DataSet->setAbscissa('Dias'); $Graph = new pImage(700, 230, $DataSet); $Graph->setFontProperties(array('FontName' => 'exemplos/graficos/pChart/fonts/verdana.ttf', 'FontSize' => 8)); $Graph->setGraphArea(50, 40, 670, 190); $scale = array('GridR' => 150, 'GridG' => 150, 'GridB' => 150, 'DrawSubTicks' => true, 'CycleBackground' => true); $Graph->drawScale($scale); if ($tipo == 'linha') { $Graph->drawLineChart(); } else { $Graph->drawBarChart(); } $Graph->drawLegend(540, 25, array('Style' => LEGEND_ROUND, 'Mode' => LEGEND_VERTICAL)); $Graph->drawText(60, 20, "Horas Trabalhadas"); $Graph->autoOutput(); }
$abscissa = $field; $myData->setAbscissa($abscissa); } else { if (isset($chart_cols2) and in_array($idx, $chart_cols2)) { $arrSeriesY2[] = $field; $myData->setSerieOnAxis($field, 1); $myData->setSerieDescription($field, "右){$field}"); } } $nSerie += 1; } } if (isset($arrSeriesY2)) { $myData->setAxisPosition(1, AXIS_POSITION_RIGHT); } $myData->setAxisUnit(0, $unitY); /* Write the chart legend */ $sizeLegend = $myPicture->getLegendSize(array("Mode" => LEGEND_VERTICAL)); $widthLegend = min($sizeLegend['Width'], max(120, $width * 0.25)); if ($legend > 0) { $myPicture->setFontProperties(array("FontName" => "./fonts/simsun.ttc", "FontSize" => $font, "R" => 0, "G" => 0, "B" => 0)); $myPicture->drawLegend($width - 5 - $widthLegend, 5 + $font_t * 3, array("Style" => LEGEND_BOX, "Mode" => LEGEND_VERTICAL, "Alpha" => 10, "Margin" => 4, "R" => 255, "G" => 255, "B" => 255)); } $myPicture->setFontProperties(array("FontName" => "./fonts/simhei.ttf", "FontSize" => $font, "R" => 0, "G" => 0, "B" => 0)); /* Define the chart area */ $width_offset = 0; if ($legend > 0) { $width_offset += max($widthLegend, 50); } if (isset($arrSeriesY2)) { $width_offset += 15 + $font * 3;
$myData->addPoints(cos(deg2rad($i)) * 20, "Probe 1"); } for ($i = 0; $i <= 360; $i = $i + 10) { $myData->addPoints(sin(deg2rad($i)) * 20, "Probe 2"); } $myData->setAxisName(0, "Index"); $myData->setAxisXY(0, AXIS_X); $myData->setAxisPosition(0, AXIS_POSITION_BOTTOM); /* Create the Y axis and the binded series */ for ($i = 0; $i <= 360; $i = $i + 10) { $myData->addPoints($i, "Probe 3"); } $myData->setSerieOnAxis("Probe 3", 1); $myData->setAxisName(1, "Degree"); $myData->setAxisXY(1, AXIS_Y); $myData->setAxisUnit(1, "°"); $myData->setAxisPosition(1, AXIS_POSITION_RIGHT); /* Create the 1st scatter chart binding */ $myData->setScatterSerie("Probe 1", "Probe 3", 0); $myData->setScatterSerieDescription(0, "This year"); $myData->setScatterSerieColor(0, array("R" => 0, "G" => 0, "B" => 0)); /* Create the 2nd scatter chart binding */ $myData->setScatterSerie("Probe 2", "Probe 3", 1); $myData->setScatterSerieDescription(1, "Last Year"); $myData->setScatterSeriePicture(1, "resources/accept.png"); /* Create the pChart object */ $myPicture = new pImage(400, 400, $myData); /* Draw the background */ $Settings = array("R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107); $myPicture->drawFilledRectangle(0, 0, 400, 400, $Settings); /* Overlay with a gradient */
function PlotLine($rowX, $rowY, $name, $ch) { include $_SERVER['DOCUMENT_ROOT'] . "/TBSIM/Lib/class/pData.class.php"; include $_SERVER['DOCUMENT_ROOT'] . "/TBSIM/Lib/class/pDraw.class.php"; include $_SERVER['DOCUMENT_ROOT'] . "/TBSIM/Lib/class/pImage.class.php"; include $_SERVER['DOCUMENT_ROOT'] . "/TBSIM/Lib/class/pPie.class.php"; //************************************** $myData = new pData(); $myData->addPoints($rowX, "Serie1"); $myData->setSerieDescription("Serie1", $name); //$myData->setSerieOnAxis("Serie1",0); $myData->addPoints($rowY, "Absissa"); $myData->setAbscissa("Absissa"); //$myData->addPoints(array("January","February","March","April","May","June","July","August"),"Absissa"); //$myData->setAbscissa("Absissa"); $myData->setAxisPosition(0, AXIS_POSITION_LEFT); //$myData->setAxisName(0,"1st axis"); $myData->setAxisUnit(0, ""); $myPicture = new pImage(700, 230, $myData); $Settings = array("R" => 240, "G" => 242, "B" => 241, "Dash" => 1, "DashR" => 260, "DashG" => 262, "DashB" => 261); $myPicture->drawFilledRectangle(0, 0, 700, 230, $Settings); $Settings = array("StartR" => 252, "StartG" => 255, "StartB" => 254, "EndR" => 252, "EndG" => 255, "EndB" => 254, "Alpha" => 50); $myPicture->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $Settings); $myPicture->drawRectangle(0, 0, 699, 229, array("R" => 0, "G" => 0, "B" => 0)); $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 50, "G" => 50, "B" => 50, "Alpha" => 20)); $myPicture->setFontProperties(array("FontName" => "fonts/Forgotte.ttf", "FontSize" => 14)); $TextSettings = array("Align" => TEXT_ALIGN_MIDDLEMIDDLE, "R" => 252, "G" => 252, "B" => 252, "DrawBox" => 1, "BoxAlpha" => 30); //$myPicture->drawText(350,25,$name,$TextSettings); $myPicture->setShadow(FALSE); $myPicture->setGraphArea(50, 50, 675, 190); //$myPicture->setFontProperties(array("R"=>0,"G"=>0,"B"=>0,"FontName"=>"fonts/pf_arma_five.ttf","FontSize"=>6)); $Settings = array("Pos" => SCALE_POS_LEFTRIGHT, "Mode" => SCALE_MODE_FLOATING, "LabelingMethod" => LABELING_ALL, "GridR" => 255, "GridG" => 255, "GridB" => 255, "GridAlpha" => 50, "TickR" => 0, "TickG" => 0, "TickB" => 0, "TickAlpha" => 50, "LabelRotation" => 0, "CycleBackground" => 1, "DrawXLines" => 1, "DrawSubTicks" => 1, "SubTickR" => 255, "SubTickG" => 0, "SubTickB" => 0, "SubTickAlpha" => 50, "DrawYLines" => ALL); $myPicture->drawScale($Settings); $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 50, "G" => 50, "B" => 50, "Alpha" => 10)); $Config = ""; if ($ch == 1) { $myPicture->drawSplineChart($Config); } if ($ch == 2) { $myPicture->drawBarChart($Config); } if ($ch == 3) { $myPicture->drawLineChart($Config); } if ($ch == 4) { $myPicture->drawPlotChart($Config); } if ($ch == 5) { $myPicture->drawStepChart($Config); } if ($ch == 6) { $myPicture->drawAreaChart($Config); } if ($ch == 7) { $myPicture->drawFilledSplineChart($Config); } if ($ch == 8) { $myPicture->drawFilledStepChart($Config); } if ($ch == 9) { $myPicture->drawStackedAreaChart($Config); } $Config = array("FontR" => 0, "FontG" => 0, "FontB" => 0, "FontName" => "fonts/pf_arma_five.ttf", "FontSize" => 6, "Margin" => 6, "Alpha" => 30, "BoxSize" => 5, "Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL); $myPicture->drawLegend(563, 16, $Config); $myPicture->stroke(); }
function block_mystats_quiz_chart($avg, $high, $strAvg, $strHigh, $strTitle, $strScale, $userid) { $myQuizData = new pData(); $myQuizData->addPoints(array($avg), "Serie1"); $myQuizData->setSerieDescription("Serie1", $strAvg); $myQuizData->setSerieOnAxis("Serie1", 0); $myQuizData->addPoints(array($high), "Serie2"); $myQuizData->setSerieDescription("Serie2", $strHigh); $myQuizData->setSerieOnAxis("Serie2", 0); $myQuizData->addPoints(array(" "), "Absissa"); $myQuizData->setAbscissa("Absissa"); $myQuizData->setAxisPosition(0, AXIS_POSITION_LEFT); $myQuizData->setAxisName(0, $strScale); $myQuizData->setAxisUnit(0, ""); $myQuizPicture = new pImage(350, 230, $myQuizData); $quizSettings = array("R" => 255, "G" => 255, "B" => 255); $myQuizPicture->drawFilledRectangle(0, 0, 350, 230, $quizSettings); $myQuizPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 50, "G" => 50, "B" => 50, "Alpha" => 20)); $myQuizPicture->setFontProperties(array("FontName" => "../blocks/mystats/pChart2.1.3/fonts/GeosansLight.ttf", "FontSize" => 14)); $TextSettings = array("Align" => TEXT_ALIGN_TOPLEFT, "R" => 0, "G" => 0, "B" => 0); $myQuizPicture->drawText(25, 25, $strTitle, $TextSettings); $myQuizPicture->setShadow(FALSE); $myQuizPicture->setGraphArea(25, 70, 325, 210); $myQuizPicture->setFontProperties(array("R" => 0, "G" => 0, "B" => 0, "FontName" => "../blocks/mystats/pChart2.1.3/fonts/pf_arma_five.ttf", "FontSize" => 8)); $AxisBoundaries = array(0 => array("Min" => 0, "Max" => 110), 1 => array("Min" => 00, "Max" => 1)); $quizSettings = array("Pos" => SCALE_POS_TOPBOTTOM, "Mode" => SCALE_MODE_MANUAL, "ManualScale" => $AxisBoundaries, "LabelingMethod" => LABELING_ALL, "GridR" => 255, "GridG" => 255, "GridB" => 255, "GridAlpha" => 50, "TickR" => 0, "TickG" => 0, "TickB" => 0, "TickAlpha" => 50, "LabelRotation" => 0, "CycleBackground" => 1, "DrawXLines" => 1, "DrawSubTicks" => 1, "SubTickR" => 255, "SubTickG" => 0, "SubTickB" => 0, "SubTickAlpha" => 50, "DrawYLines" => ALL); $myQuizPicture->drawScale($quizSettings); $myQuizPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 50, "G" => 50, "B" => 50, "Alpha" => 10)); $quizConfig = array("DisplayValues" => 1, "Rounded" => 1, "AroundZero" => 1); $myQuizPicture->drawBarChart($quizConfig); $quizConfig = array("R" => 0, "G" => 0, "B" => 0, "Alpha" => 50, "AxisID" => 0, "Ticks" => 4, "Caption" => "Threshold"); $myQuizPicture->drawThreshold(0, $quizConfig); $quizConfig = array("FontR" => 0, "FontG" => 0, "FontB" => 0, "FontName" => "../blocks/mystats/pChart2.1.3/fonts/pf_arma_five.ttf", "FontSize" => 8, "Margin" => 6, "Alpha" => 30, "BoxSize" => 5, "Style" => LEGEND_ROUND, "Mode" => LEGEND_VERTICAL, "Family" => LEGEND_FAMILY_CIRCLE); $myQuizPicture->drawLegend(240, 16, $quizConfig); $imgName = sha1($userid . $strTitle) . '.png'; $myQuizPicture->Render('../blocks/mystats/img/' . $imgName); return '<img src="../blocks/mystats/img/' . $imgName . '" alt="' . $strAvg . ': ' . $avg . ', ' . $strHigh . ': ' . $high . '">'; }
<?php /* CAT:Labels */ /* pChart library inclusions */ include "../class/pData.class.php"; include "../class/pDraw.class.php"; include "../class/pImage.class.php"; /* Create and populate the pData object */ $MyData = new pData(); $MyData->addPoints(array(4, 12, 15, 8, 5, -5), "Probe 1"); $MyData->addPoints(array(7, 2, 4, 14, 8, 3), "Probe 2"); $MyData->setAxisName(0, "Temperatures"); $MyData->setAxisUnit(0, "°C"); $MyData->addPoints(array("Jan", "Feb", "Mar", "Apr", "May", "Jun"), "Labels"); $MyData->setSerieDescription("Labels", "Months"); $MyData->setAbscissa("Labels"); /* Create the pChart object */ $myPicture = new pImage(700, 230, $MyData); /* Draw the background */ $Settings = array("R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107); $myPicture->drawFilledRectangle(0, 0, 700, 230, $Settings); /* Overlay with a gradient */ $Settings = array("StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1, "EndG" => 138, "EndB" => 68, "Alpha" => 50); $myPicture->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $Settings); $myPicture->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, array("StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 80)); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, 699, 229, array("R" => 0, "G" => 0, "B" => 0)); /* Write the picture title */ $myPicture->setFontProperties(array("FontName" => "../fonts/Silkscreen.ttf", "FontSize" => 6)); $myPicture->drawText(10, 13, "drawLabel() - Write labels over your charts", array("R" => 255, "G" => 255, "B" => 255)); /* Write the chart title */
$pChart = new pData(); $chart_tile_colours = array("0" => array("R" => 246, "G" => 113, "B" => 53, "Alpha" => 100), "1" => array("R" => 211, "G" => 60, "B" => 29, "Alpha" => 100), "2" => array("R" => 80, "G" => 94, "B" => 97, "Alpha" => 100), "3" => array("R" => 131, "G" => 137, "B" => 129, "Alpha" => 100), "4" => array("R" => 42, "G" => 43, "B" => 45, "Alpha" => 100), "5" => array("R" => 116, "G" => 82, "B" => 73, "Alpha" => 100), "6" => array("R" => 190, "G" => 93, "B" => 72, "Alpha" => 100), "7" => array("R" => 95, "G" => 83, "B" => 84, "Alpha" => 100), "8" => array("R" => 220, "G" => 220, "B" => 220, "Alpha" => 100)); for ($i = 0; $i < count($colours); $i++) { $pChart->addPoints(array($tile_colour_results[0][$i], $tile_colour_results[1][$i], $tile_colour_results[2][$i], $tile_colour_results[3][$i], $tile_colour_results[4][$i], $tile_colour_results[5][$i], $tile_colour_results[6][$i], $tile_colour_results[7][$i], $tile_colour_results[8][$i], $tile_colour_results[9][$i], $tile_colour_results[10][$i], $tile_colour_results[11][$i], $tile_colour_results[12][$i]), "Serie{$i}"); $pChart->setSerieDescription("Serie{$i}", $colours[$i][0]); $pChart->setSerieOnAxis("Serie{$i}", 0); $pChart->setPalette("Serie{$i}", $chart_tile_colours[$i]); } $pChart->addPoints(array(get_tile_total_count($tile_colour_results, 0), get_tile_total_count($tile_colour_results, 1), get_tile_total_count($tile_colour_results, 2), get_tile_total_count($tile_colour_results, 3), get_tile_total_count($tile_colour_results, 4), get_tile_total_count($tile_colour_results, 5), get_tile_total_count($tile_colour_results, 6), get_tile_total_count($tile_colour_results, 7), get_tile_total_count($tile_colour_results, 8), get_tile_total_count($tile_colour_results, 9), get_tile_total_count($tile_colour_results, 10), get_tile_total_count($tile_colour_results, 11), get_tile_total_count($tile_colour_results, 12)), "Serie10"); $pChart->setSerieDrawable("Serie10", FALSE); $pChart->setPalette("Serie10", array("Alpha" => 0)); $pChart->addPoints(array("Ormax", "Protector", "Polar", "Minster", "Turmalin", "Granat", "E13", "T11", "Nova", "Rubin", "Nortegl", "Hollander", "KDN"), "Absissa"); $pChart->setAbscissa("Absissa"); $pChart->setAxisPosition(0, AXIS_POSITION_LEFT); $pChart->setAxisName(0, "Laskentamäärät kpl"); $pChart->setAxisUnit(0, ""); $pChartPicture = new pImage($width, $height, $pChart); $Settings = array("R" => 255, "G" => 255, "B" => 255); $pChartPicture->drawFilledRectangle(0, 0, $width, $height, $Settings); $pChartPicture->setFontProperties(array("FontName" => "pChart/fonts/arial.ttf", "FontSize" => 14)); $TextSettings = array("Align" => TEXT_ALIGN_BOTTOMMIDDLE, "R" => 0, "G" => 0, "B" => 0); $pChartPicture->drawText($width / 2, 25, ucfirst($table) . " - Tiilet / Värit", $TextSettings); $description .= GetYearsDescription($years); $description .= " - (" . GetSeriesTotalSum($pChart, "Half") . "kpl)"; if (strlen($description) > 120) { $description = substr($description, strpos($description, "joissa")); } $pChartPicture->setFontProperties(array("FontSize" => 11)); $pChartPicture->drawText($width / 2, 45, $description, $TextSettings); $pChartPicture->setGraphArea(50, 55, $width - 25, $height - 75); $pChartPicture->setFontProperties(array("R" => 0, "G" => 0, "B" => 0, "FontName" => "pChart/fonts/arial.ttf", "FontSize" => 10));
require_once 'pChart/class/pDraw.class.php'; require_once 'pChart/class/pImage.class.php'; require_once 'pChart/class/pData.class.php'; // Exemplo extraido do site da lib // precisamos ter dados para montar os gráficos $DataSet = new pData(); // Adicionando os pontos de um gráfico de linha // horas de trabalho na semana $DataSet->addPoints(array(8, 9, 11, 6.5, 6, 5), "Joao"); // João $DataSet->addPoints(array(7.5, 8, 7.5, 10, 6, 6), "Pedro"); // Pedro $DataSet->setAxisName(0, 'Horas'); // unidade $DataSet->setAxisUnit(0, 'h'); // Labels $DataSet->addPoints(array('Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado'), 'Dias'); $DataSet->setSerieDescription('Dias', 'Dias da Semana'); $DataSet->setAbscissa('Dias'); // Inicializando o gráfico - Largura e Altura $Graph = new pImage(700, 230, $DataSet); // Fonte padrão para os textos $Graph->setFontProperties(array('FontName' => "pChart/fonts/verdana.ttf", 'FontSize' => 8)); // Área utilizada para plotar o gráfico - x1, y1, x2, y2 $Graph->setGraphArea(50, 40, 670, 190); // RGB, Subticks no eixo, Fundo cores alternadas // ver: http://wiki.pchart.net/doc.doc.draw.scale.html $scale = array('GridR' => 150, 'GridG' => 150, 'GridB' => 150, 'DrawSubTicks' => true, 'CycleBackground' => true); $Graph->drawScale($scale); $Graph->drawBarChart();
<?php /* CAT:Combo */ /* pChart library inclusions */ include "../class/pData.class.php"; include "../class/pDraw.class.php"; include "../class/pImage.class.php"; include "../class/pIndicator.class.php"; /* Create and populate the pData object */ $MyData = new pData(); for ($i = 0; $i <= 80; $i++) { $MyData->addPoints($i / 10 * ($i / 10), "Statistical probability"); } $MyData->setAxisName(0, "Probability"); $MyData->setAxisUnit(0, "%"); /* Create the pChart object */ $myPicture = new pImage(700, 350, $MyData); /* Turn of Antialiasing */ $myPicture->Antialias = FALSE; /* Draw the background */ $Settings = array("R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107); $myPicture->drawFilledRectangle(0, 0, 700, 350, $Settings); /* Overlay with a gradient */ $Settings = array("StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1, "EndG" => 138, "EndB" => 68, "Alpha" => 50); $myPicture->drawGradientArea(0, 0, 700, 220, DIRECTION_VERTICAL, $Settings); $Settings = array("StartR" => 1, "StartG" => 138, "StartB" => 68, "EndR" => 219, "EndG" => 231, "EndB" => 239, "Alpha" => 50); $myPicture->drawGradientArea(0, 222, 700, 350, DIRECTION_VERTICAL, $Settings); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, 699, 349, array("R" => 0, "G" => 0, "B" => 0)); /* Set the default font */ $myPicture->setFontProperties(array("FontName" => "../fonts/pf_arma_five.ttf", "FontSize" => 6));
} $Data = $Data . "," . toString($Value); } $Data = right($Data, strlen($Data) - 1); echo '$myData->addPoints(array(' . $Data . '),"Absissa");' . "\r\n"; echo '$myData->setAbscissa("Absissa");' . "\r\n\r\n"; } } if (isset($Axis[0])) { if ($d_axis0_position == "left") { $myData->setAxisPosition(0, AXIS_POSITION_LEFT); } else { $myData->setAxisPosition(0, AXIS_POSITION_RIGHT); } $myData->setAxisName(0, $d_axis0_name); $myData->setAxisUnit(0, $d_axis0_unit); if ($d_axis0_format == "AXIS_FORMAT_METRIC") { $myData->setAxisDisplay(0, 680004); } if ($d_axis0_format == "AXIS_FORMAT_CURRENCY") { $myData->setAxisDisplay(0, 680005, "\$"); } if ($Mode == "Source") { if ($d_axis0_position == "left") { echo '$myData->setAxisPosition(0,AXIS_POSITION_LEFT);' . "\r\n"; } else { echo '$myData->setAxisPosition(0,AXIS_POSITION_RIGHT);' . "\r\n"; } echo '$myData->setAxisName(0,"' . $d_axis0_name . '");' . "\r\n"; echo '$myData->setAxisUnit(0,"' . $d_axis0_unit . '");' . "\r\n\r\n"; }
$DataSet->AddPoints(0, "Serie1"); //$DataSet->AddPoints(0,"Serie3"); } if ($_GET['op'] == 'values') { echo json_encode($values); exit; } if ($_GET['op'] == 'json') { //header("Content-type: text/json"); $ret = array(); $ret['VALUES'] = $values; $ret['TIME'] = $hours; echo json_encode($ret); exit; } $DataSet->setAxisUnit(0, $unit); $DataSet->addPoints($hours, "Labels"); $DataSet->setSerieDescription("Labels", "Время"); $DataSet->setAbscissa("Labels"); //цвет графика if ($_GET['gcolor'] == 'red') { $ColorPalete = array("R" => 220, "G" => 50, "B" => 50); } elseif ($_GET['gcolor'] == 'brown') { $ColorPalete = array("R" => 220, "G" => 140, "B" => 100); } elseif ($_GET['gcolor'] == 'blue') { $ColorPalete = array("R" => 100, "G" => 140, "B" => 220); } elseif ($_GET['gcolor'] == 'green') { $ColorPalete = array("R" => 69, "G" => 139, "B" => 16); } elseif ($_GET['gcolor'] == 'orange') { $ColorPalete = array("R" => 255, "G" => 140, "B" => 0); } else {
function electrique_mois() { //initialisation des variables tableau $timestamp = ""; $conso = ""; $sql = mysql_query("SELECT TIMESTAMP(CONCAT(YEAR(date_histo ),'-',MONTH(date_histo ),'-',DAY(date_histo ),' ',HOUR(date_histo ),':00')),\n\t\t\t\t\tdate_histo, AVG(valeur1),MAX(valeur1),MIN(valeur1)\n\t\t\t\t\tFROM historique_donnees\n\t\t\t\t\tWHERE id_objet = 2\n\t\t\t\t\tAND date_histo > DATE_SUB(NOW( ), INTERVAL 31 DAY)\n\t\t\t\t\tGROUP BY YEAR( date_histo ) , MONTH( date_histo ) , DAY( date_histo ), HOUR( date_histo ), id_objet\n\t\t\t\t\tHAVING HOUR( date_histo ) IN ( 00, 06, 12, 18 ) \n\t\t\t\t\tORDER BY date_histo"); while (list($date_histo, $date_histo2, $conso_sql, $conso_sql_max, $conso_sql_min) = mysql_fetch_array($sql)) { $timestamp[] = strtotime($date_histo); $conso[] = $conso_sql; $conso_max[] = $conso_sql_max; $conso_min[] = $conso_sql_min; } $myData = new pData(); $myData->addPoints($timestamp, "Timestamp"); $myData->addPoints($conso, "Consommation Instantanée Moyenne"); $myData->addPoints($conso_max, "Conso. Inst. Max"); $myData->addPoints($conso_min, "Conso. Inst. Min"); $myData->setSerieOnAxis("Consommation Instantanée", 0); $myData->setSerieOnAxis("Conso. Inst. Max", 0); $myData->setSerieOnAxis("Conso. Inst. Min", 0); $myData->setAbscissa("Timestamp"); $myData->setXAxisName("Time"); $myData->setXAxisDisplay(AXIS_FORMAT_TIME, "d/m"); $myData->setAxisName(0, "Consommation Instantanée"); $myData->setAxisUnit(0, "W"); $myPicture = new pImage(1250, 550, $myData); $Settings = array("StartR" => 48, "StartG" => 124, "StartB" => 183, "EndR" => 33, "EndG" => 86, "EndB" => 128, "Alpha" => 50); $myPicture->drawGradientArea(0, 0, 1250, 550, DIRECTION_VERTICAL, $Settings); $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 50, "G" => 50, "B" => 50, "Alpha" => 20)); $myPicture->setFontProperties(array("FontName" => "fonts/Forgotte.ttf", "FontSize" => 18)); $TextSettings = array("Align" => TEXT_ALIGN_MIDDLEMIDDLE, "R" => 255, "G" => 255, "B" => 255); $myPicture->drawText(350, 25, "Consommation éléctrique", $TextSettings); $myPicture->setShadow(FALSE); $myPicture->setGraphArea(110, 50, 1160, 500); $myPicture->setFontProperties(array("R" => 0, "G" => 0, "B" => 0, "FontName" => "fonts/Forgotte.ttf", "FontSize" => 14)); $Settings = array("Pos" => SCALE_POS_LEFTRIGHT, "Mode" => SCALE_MODE_FLOATING, "LabelingMethod" => LABELING_ALL, "GridR" => 255, "GridG" => 255, "GridB" => 255, "GridAlpha" => 50, "TickR" => 0, "TickG" => 0, "TickB" => 0, "TickAlpha" => 50, "LabelRotation" => 45, "CycleBackground" => 1, "DrawXLines" => 1, "DrawSubTicks" => 1, "SubTickR" => 255, "SubTickG" => 0, "SubTickB" => 0, "SubTickAlpha" => 50, "DrawYLines" => ALL, "LabelSkip" => 3); $myPicture->drawScale($Settings); $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 50, "G" => 50, "B" => 50, "Alpha" => 10)); $Config = ""; $myPicture->drawSplineChart($Config); $Config = array("FontR" => 0, "FontG" => 0, "FontB" => 0, "FontName" => "fonts/Forgotte.ttf", "FontSize" => 14, "Margin" => 6, "Alpha" => 30, "BoxSize" => 5, "Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL); $myPicture->drawLegend(563, 16, $Config); $myPicture->render("tmp/graphe_em.png"); echo "<img src='tmp/graphe_em.png' alt='graphe'/>"; }
include dirname(dirname(dirname(__FILE__))) . '/lib/pchart2/class/pDraw.class'; include dirname(dirname(dirname(__FILE__))) . '/lib/pchart2/class/pImage.class'; include dirname(dirname(dirname(__FILE__))) . '/lib/pchart2/class/pData.class'; include dirname(dirname(dirname(__FILE__))) . '/lib/pchart2/class/pRadar.class'; $COLORS = ArtefactTypeSurvey::get_palette_colors($PALETTE); /* Create your dataset object */ $myData = new pData(); /* Add data in your dataset */ $POINTS = array(); $LABELS = array(); foreach ($DATA as $value) { $POINTS[] = $value['value']; $LABELS[] = $value['key']; } $myData->addPoints($POINTS, $CONFIG['title']); $myData->setAxisUnit(0, ''); /* Labels definition */ $myData->addPoints($LABELS, 'Legend'); $myData->setSerieDescription('Legend', ''); $myData->setAbscissa('Legend'); /* Will replace the whole color scheme by the selected palette */ $myData->loadPalette(dirname(dirname(dirname(__FILE__))) . '/lib/pchart2/palettes/' . $PALETTE . '.color', TRUE); /* Create a pChart object and associate your dataset */ $myPicture = new pImage($WIDTH, $HEIGHT, $myData); /* Draw border around the chart */ $myPicture->drawRectangle(0, 0, $WIDTH - 1, $HEIGHT - 1, array("R" => 0, "G" => 0, "B" => 0)); /* Draw chart background */ $myPicture->drawFilledRectangle(0, 0, $WIDTH, $HEIGHT, array("R" => $COLORS[1]['R'], "G" => $COLORS[1]['G'], "B" => $COLORS[1]['B'], "Alpha" => 10)); /* Define the boundaries of the graph area */ $myPicture->setGraphArea(20, 20, $WIDTH - 20, $HEIGHT - 40); /* Choose a nice font */
$myData->setSerieOnAxis($key, 0); } //$myData->addPoints(array(28,-19,18,4,-2,-31,17,48),"Serie1"); //$myData->setSerieDescription("Serie1","Serie 1"); //$myData->setSerieOnAxis("Serie1",0); // //$myData->addPoints(array(-37,37,-38,16,-4,39,29,6),"Serie2"); //$myData->setSerieDescription("Serie2","Serie 2"); //$myData->setSerieOnAxis("Serie2",0); // //$myData->addPoints(array(16,46,-32,35,32,-15,40,29),"Serie3"); //$myData->setSerieDescription("Serie3","Serie 3"); //$myData->setSerieOnAxis("Serie3",0); $myData->setAxisPosition(0, AXIS_POSITION_LEFT); $myData->setAxisName(0, "Notas"); $myData->setAxisUnit(0, ""); $myData->addPoints(array("1er Trimestre", "2ndo Trimestre", "3er Trimestre"), "Absissa"); $myData->setAbscissa("Absissa"); //$myData->addPoints(array("1","2","3"),"Labels"); //$myData->setSerieDescription("Labels","Evaluaciones"); //$myData->setAbscissa("Labels"); $myPicture = new pImage($anchura, $altura, $myData); $Settings = array("R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107); $myPicture->drawFilledRectangle(0, 0, $anchura, $altura, $Settings); if ($g_enabled == "on") { list($StartR, $StartG, $StartB) = extractColors($g_gradient_start); list($EndR, $EndG, $EndB) = extractColors($g_gradient_end); $Settings = array("StartR" => $StartR, "StartG" => $StartG, "StartB" => $StartB, "EndR" => $EndR, "EndG" => $EndG, "EndB" => $EndB, "Alpha" => 50); //$Settings = array("StartR"=>125, "StartG"=>92, "StartB"=>231, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50); if ($g_direction == "vertical") { $myPicture->drawGradientArea(0, 0, $anchura, $altura, DIRECTION_VERTICAL, $Settings);
/* Set X-Axis */ $MyData->setAbscissa("Timestamp"); /* Set X-Axis name */ $MyData->setXAxisName("Time"); /* Setup Series Y-Axis 0 */ $MyData->setSerieOnAxis("Temperature", 0); /* Setup Series Y-Axis 1 */ $MyData->setSerieOnAxis("Humidity", 1); /* Setup Series Y-Axis 1 Location */ $MyData->setAxisPosition(1, AXIS_POSITION_RIGHT); /* Set Y-Axis Series 0 name */ $MyData->setAxisName(0, "Temperature"); /* Set Y-Axis Series 1 name */ $MyData->setAxisName(1, "Humidity"); /* Set Y-Axis Series 0 Units */ $MyData->setAxisUnit(0, "°C"); /* Set Y-Axis Series 1 Units */ $MyData->setAxisUnit(1, "%"); //////////////////////////////////////////////////////////////// // Maximum Values // /* Get maximum Temperature Value */ $temp = $MyData->getMax("Temperature"); /* Get maximum Temperature Value */ $T_Maximum = number_format($temp, 1); /* Get maximum Humidity Value */ $temp = $MyData->getMax("Humidity"); /* Format Max to 1 decimal place */ $H_Maximum = number_format($temp, 1); //////////////////////////////////////////////////////////////// // Average Values
<?php /* CAT:Scaling */ /* pChart library inclusions */ include "../class/pData.class.php"; include "../class/pDraw.class.php"; include "../class/pImage.class.php"; /* Create and populate the pData object */ $MyData = new pData(); $MyData->addPoints(array(1700, 2500, 7800, 4500, 3150), "Distance"); $MyData->setAxisName(0, "Maximum distance"); $MyData->setAxisUnit(0, "m"); $MyData->setAxisDisplay(0, AXIS_FORMAT_METRIC); /* Create the abscissa serie */ $MyData->addPoints(array(1230768000, 1233446400, 1235865600, 1238544000, 1241136000, 1243814400), "Timestamp"); $MyData->setSerieDescription("Timestamp", "Sampled Dates"); $MyData->setAbscissa("Timestamp"); $MyData->setXAxisDisplay(AXIS_FORMAT_DATE); /* Create the pChart object */ $myPicture = new pImage(700, 230, $MyData); /* Draw the background */ $Settings = array("R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107); $myPicture->drawFilledRectangle(0, 0, 700, 230, $Settings); /* Overlay with a gradient */ $Settings = array("StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1, "EndG" => 138, "EndB" => 68, "Alpha" => 50); $myPicture->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $Settings); $myPicture->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, array("StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 80)); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, 699, 229, array("R" => 0, "G" => 0, "B" => 0)); /* Write the picture title */ $myPicture->setFontProperties(array("FontName" => "../fonts/Silkscreen.ttf", "FontSize" => 6));
function draw_3dpie_chart($WIDTH, $HEIGHT, $DATA, $CONFIG, $LEGEND, $FONT, $PALETTE = 'default') { /* Include all the pChart 2.0 classes */ include '../lib/pchart2/class/pDraw.class'; include '../lib/pchart2/class/pImage.class'; include '../lib/pchart2/class/pData.class'; include '../lib/pchart2/class/pPie.class'; $COLORS = ArtefactTypeSurvey::get_palette_colors($PALETTE); /* Create your dataset object */ $myData = new pData(); /* Add data in your dataset */ if ($CONFIG['type'] == 'percent') { foreach ($DATA[0] as $value) { if ($value['percent'] != 0) { $POINTS[] = $value['percent']; if ($LEGEND == 'key') { $LABELS[] = $value['key']; } if ($LEGEND == 'label') { $LABELS[] = $value['label']; } } } $myData->addPoints($POINTS, $CONFIG['title']); $myData->setAxisUnit(0, '%'); } else { foreach ($DATA[0] as $value) { if ($value['value'] != 0) { $POINTS[] = $value['value']; if ($LEGEND == 'key') { $LABELS[] = $value['key']; } if ($LEGEND == 'label') { $LABELS[] = $value['label']; } } } $myData->addPoints($POINTS, $CONFIG['title']); $myData->setAxisUnit(0, ''); } /* Labels definition */ /* $myData->addPoints($LABELS,'Legend'); $myData->setSerieDescription('Legend',''); $myData->setAbscissa('Legend'); */ /* Will replace the whole color scheme by the selected palette */ $myData->loadPalette('lib/pchart2/palettes/' . $PALETTE . '.color', TRUE); /* Create a pChart object and associate your dataset */ $myPicture = new pImage($WIDTH, $HEIGHT, $myData); /* Draw border around the chart */ $myPicture->drawRectangle(0, 0, $WIDTH - 1, $HEIGHT - 1, array("R" => 0, "G" => 0, "B" => 0)); /* Draw chart background */ //$myPicture->drawFilledRectangle(0,0,$WIDTH,$HEIGHT,array("R"=>$COLORS[1]['R'],"G"=>$COLORS[1]['G'],"B"=>$COLORS[1]['B'],"Alpha"=>10)); /* Define the boundaries of the graph area */ //$myPicture->setGraphArea(20,20,$WIDTH-20,$HEIGHT-40); /* Choose a nice font */ switch ($FONT['type']) { case 'serif': $fontname = 'lib/pchart2/fonts/LiberationSerif-Regular.ttf'; break; case 'sans': $fontname = 'lib/pchart2/fonts/LiberationSans-Regular.ttf'; break; } $myPicture->setFontProperties(array('FontName' => $fontname, 'FontSize' => $FONT['size'])); /* Create label with survey name */ //$myPicture->drawText(20,$HEIGHT-30,$CONFIG['title'],array("DrawBox"=>true,"BoxRounded"=>true,"BoxR"=>$COLORS[1]['R'],"BoxG"=>$COLORS[1]['G'],"BoxB"=>$COLORS[1]['B'],"BoxAlpha"=>20,"Align"=>TEXT_ALIGN_MIDDLELEFT)); /* Create the pPie object */ $PieChart = new pPie($myPicture, $myData); /* Draw a simple pie chart */ $PIE_WIDTH = $WIDTH - 40; // 20px margin on left and right $PIE_HEIGHT = $HEIGHT - 60; // 20px margin on top and 40px on bottom (space for legend) if ($PIE_WIDTH >= $PIE_HEIGHT) { // Landscape orientation of the graph... $PieRadius = round($PIE_HEIGHT / 2); } else { // Portrait orientation of the graph... $PieRadius = round($PIE_WIDTH / 2); } $PieX = round($WIDTH / 2); $PieY = round($HEIGHT / 2); $PieChart->draw3DPie($PieX, $PieY, array("Radius" => $PieRadius, "SecondPass" => false, "DrawLabels" => false)); /* Build the PNG file and send it to the web browser */ $myPicture->Stroke(); }