Blame | Last modification | View Log | RSS feed
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><title>5.6. Example - Bar Chart, Label Options</title><link rel="stylesheet" type="text/css" href="phplotdoc.css" /><meta name="generator" content="DocBook XSL Stylesheets V1.78.1" /><link rel="home" href="index.html" title="PHPlot Reference Manual" /><link rel="up" href="examples.html" title="Chapter 5. PHPlot Examples" /><link rel="prev" href="ex-bars2.html" title="5.5. Example - Unshaded Bar Chart" /><link rel="next" href="ex-linepoints1.html" title="5.7. Example - Line/Point Plot, Point Shapes" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.6. Example - Bar Chart, Label Options</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ex-bars2.html">Prev</a> </td><th width="60%" align="center">Chapter 5. PHPlot Examples</th><td width="20%" align="right"> <a accesskey="n" href="ex-linepoints1.html">Next</a></td></tr></table><hr /></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ex-bars3"></a>5.6. Example - Bar Chart, Label Options</h2></div></div></div><p>This is a bar chart showing data per year. Because the Y values are solarge, we enable numeric formatting of Y tick labels, with precision 0.This results in a comma separator between thousands.This example also shows how to force the Y tick marks to start at zero anduse a nice whole number for the tick interval.</p><div class="example"><a id="example-bars3"></a><p class="title"><strong>Example 5.6. Bar Chart - Label Options</strong></p><div class="example-contents"><div class="informalfigure"><div class="mediaobject"><img src="examples/bars3.png" alt="Bar Chart with Labels Example" /></div></div><pre class="programlisting"><?php# PHPlot Example: Bar chart, annual datarequire_once 'phplot.php';$data = array(array('1985', 340), array('1986', 682), array('1987', 1231),array('1988', 2069), array('1989', 3509), array('1990', 5283),array('1991', 7557), array('1992', 11033), array('1993', 16009),array('1994', 24134), array('1995', 33768), array('1996', 44043),array('1997', 55312), array('1998', 69209), array('1999', 86047),array('2000', 109478), array('2001', 128375), array('2002', 140767),);$plot = new PHPlot(800, 600);$plot->SetImageBorderType('plain');$plot->SetPlotType('bars');$plot->SetDataType('text-data');$plot->SetDataValues($data);# Let's use a new color for these bars:$plot->SetDataColors('magenta');# Force bottom to Y=0 and set reasonable tick interval:$plot->SetPlotAreaWorld(NULL, 0, NULL, NULL);$plot->SetYTickIncrement(10000);# Format the Y tick labels as numerics to get thousands separators:$plot->SetYLabelType('data');$plot->SetPrecisionY(0);# Main plot title:$plot->SetTitle('US Cell Phone Subscribership');# Y Axis title:$plot->SetYTitle('Thousands of Subscribers');# Turn off X tick labels and ticks because they don't apply here:$plot->SetXTickLabelPos('none');$plot->SetXTickPos('none');$plot->DrawGraph();</pre></div></div><br class="example-break" /></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ex-bars2.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="examples.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ex-linepoints1.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.5. Example - Unshaded Bar Chart </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5.7. Example - Line/Point Plot, Point Shapes</td></tr></table></div></body></html>