/** * Based on Example24.php */ public function testXYChart() { // Dataset definition $DataSet = new pData(); // Compute the points for ($i = 0; $i <= 360; $i = $i + 10) { $DataSet->addPoint(cos($i * 3.14 / 180) * 80 + $i, "Serie1"); $DataSet->addPoint(sin($i * 3.14 / 180) * 80 + $i, "Serie2"); } $DataSet->setSeriesName("Trigonometric function", "Serie1"); $DataSet->addSeries("Serie1"); $DataSet->addSeries("Serie2"); $DataSet->SetXAxisName("X Axis"); $DataSet->SetYAxisName("Y Axis"); // Initialise the graph $canvas = new TestCanvas(); $Test = new pChart(300, 300, $canvas); $Test->drawBackgroundGradient(new Color(0), -100); // Prepare the graph area $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->setGraphArea(55, 30, 270, 230); $scaleStyle = new ScaleStyle(SCALE_NORMAL, new Color(213, 217, 221)); $Test->drawXYScale($DataSet, $scaleStyle, "Serie1", "Serie2", 45); $backgroundStyle = new BackgroundStyle(new Color(213, 217, 221), FALSE, new Color(30), -50); $Test->drawGraphBackground($backgroundStyle); $Test->drawGrid(new GridStyle(4, TRUE, new Color(230), 20)); // Draw the chart $Test->setShadowProperties(2, 2, new Color(0), 60, 4); $Test->drawXYGraph($DataSet->GetData(), "Serie1", "Serie2", 0); $Test->clearShadow(); // Draw the title $Title = "Drawing X versus Y charts trigonometric functions "; $Test->drawTextBox(new Point(0, 280), new Point(300, 300), $Title, 0, new Color(255), ALIGN_RIGHT, ShadowProperties::FromSettings(1, 1, new Color(0), 100, 0), new Color(0), 30); // Draw the legend $Test->setFontProperties("Fonts/pf_arma_five.ttf", 6); $DataSet->removeSeries("Serie2"); $Test->drawLegend(160, 5, $DataSet->GetDataDescription(), new Color(0), new Color(0), new Color(255), FALSE); file_put_contents(dirname(__FILE__) . '/action_logs/testXYChart', $canvas->getActionLog()); $this->assertEquals('3c45517b3d9549198ffffaac276ad353', md5($canvas->getActionLog())); }
public function testRemoveSeries() { $data = new pData(); $data->addPoint(array(1, 2), 'testseries1'); $data->addPoint(array(3, 4), 'testseries2'); $data->addSeries('testseries1'); $data->addSeries('testseries2'); $this->assertEquals(array('Position' => 'Name', 'Format' => array('X' => 'number', 'Y' => 'number'), 'Unit' => array('X' => null, 'Y' => null), 'Values' => array('testseries1', 'testseries2')), $data->getDataDescription()); $data->removeSeries('testseries1'); $this->assertEquals(array('Position' => 'Name', 'Format' => array('X' => 'number', 'Y' => 'number'), 'Unit' => array('X' => null, 'Y' => null), 'Values' => array(1 => 'testseries2')), $data->getDataDescription()); }
public function testAddPoint() { $data = new pData(); $data->addPoint(1); $this->assertEquals(array(0 => array('Series1' => 1, 'Name' => 0)), $data->getData()); $data->addPoints(array(2, 3, 4)); $this->assertEquals(array(0 => array('Series1' => 1, 'Name' => 0), 1 => array('Series1' => 2, 'Name' => 1), 2 => array('Series1' => 3, 'Name' => 2), 3 => array('Series1' => 4, 'Name' => 3)), $data->getData()); }