Menu

squarefilled

PHPlot Samples - Filled Squared Plot

Here are 2 examples of a 'filled squared' plot.
2015-03-05

Reference: Discussion forum thread

Code Example 1: Using a bar chart

:::php
<?php
# PHPlot Forum 2015-03-05 : Square Filled Plot
# Using a bar chart, adjusted widths, no outlines.
require_once 'phplot.php';

// Some data to plot:
$data = array();
for ($i = 0; $i < 10; $i++)
    $data[] = array('', $i**2 - 4 * $i + 5);

$p = new PHPlot(800, 600);
$p->SetTitle('Square Filled');
$p->SetDataType('text-data');
$p->SetDataValues($data);
$p->SetPlotType('bars');

// See Chapter 4.7.1 Tuning Bar Charts
// This makes the bars full width:
$p->bar_extra_space = 0;
$p->group_frac_width = 1;
// No shading and no borders on the bars:
$p->SetShading(0);
$p->SetDrawDataBorders(False);

$p->DrawGraph();

~~~~~

### Code Example 2: Using an area plot ###

Note: The data array has to be specially created for this. It traces out the stair-steps of the line. It looks something like this: (0,0) (0,Y1) (X1,Y1) (X1,Y2) (X2,Y2) ... That is, each point is doubled, and only one of either X or Y changes at each point.

:::php
<?php

PHPlot Forum 2015-03-05 : Square Filled Plot

Using an area plot.

require_once 'phplot.php';

// Some data to plot:
$x = 0;
$y = 0;
$data = array(array('', $x, $y));
for ($i = 0; $i < 10; $i++) {
$y = $x ** 2 - 4 * $x + 5;
$data[] = array('', $x, $y);
$x++;
$data[] = array('', $x, $y);
}

$p = new PHPlot(800, 600);
$p->SetTitle('Square Filled');
$p->SetDataType('data-data');
$p->SetDataValues($data);
$p->SetPlotType('area');

$p->DrawGraph();

~~~~~

The Plot:

Both above scripts produce the same image:

Plot Image


Related

Discussion: Plotting a 'squared' graph with a fill below the line (= area with straight lines)

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.