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

SetTitle('Square Filled'); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetPlotType('area'); $p->DrawGraph(); ~~~~~ ### The Plot: ### Both above scripts produce the same image: [[img src=square-filled.png alt="Plot Image"]] ?>

Related

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