Menu

SampleYAxisDefaultChange

PHPlot Sample - Y Axis Default Change

Editor's note: This page was originally written up on 2010-09-23. The referenced bug fix was implemented in PHPlot-5.2.0.

To fix Bug: Fix Y axis default for horizontal plots the code for calculating the default X and Y axis positions was changed after PHPlot-5.1.3. There was no change for normal (vertical) plots. For horizontal plots, the methods for calculating X and Y axis default positions were swapped. The change affects horizontal thinbarline and horizontal bar plots, which contain negative values, where the Y axis is not positioned with SetYAxisPosition().

PHPlot through 5.1.3 will place the Y axis at the left side of the graph, and the bars will extend rightward for both negative and positive values. (See first figure below.) After the bug fix, the Y axis will be placed at X=0 if it is within the plot, and the bars will extend rightward for positive values and leftward for negative values. (See the second figure below.) Of course, you can override the defaults by setting the axis positions with SetXAxisPosition() and SetYAxisPosition().

The following figures illustrate the result of the change.

Result using PHPlot-5.1.3:

Before plot image

Result after the bug fix:

After plot image

The Code:

~~~~
:::php
<?php

Y Axis Default Change demonstration

This is a horizontal bar chart with positive and negative values

require 'phplot.php';
$data = array(
array('Pos1', 10),
array('Pos2', 0),
array('Pos3', 40),
array('Pos4', 100),
array('Pos5', 80),
array('Neg1', -10),
array('Neg2', -100),
array('Neg3', -5),
array('Neg4', -70),
array('Neg6', 0),
);

$p = new PHPlot(600, 600);
$p->SetTitle('Horizontal Bar Chart - Y Axis position');
$p->SetDataValues($data);
$p->SetDataType('text-data-yx');
$p->SetPlotType('bars');
$p->SetXDataLabelPos('plotin');
$p->SetYTickPos('none');
$p->DrawGraph();

~~~~~


Related

Bugs: #145

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.