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.28. Example - Horizontal Stacked Bar Chart</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-horizbar.html" title="5.27. Example - Horizontal Bar Chart" /><link rel="next" href="ex-horizthinbarline.html" title="5.29. Example - Horizontal Thin Bar Line Plot" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.28. Example - Horizontal Stacked Bar Chart</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ex-horizbar.html">Prev</a></td><th width="60%" align="center">Chapter 5. PHPlot Examples</th><td width="20%" align="right"> <a accesskey="n" href="ex-horizthinbarline.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-horizstackedbar"></a>5.28. Example - Horizontal Stacked Bar Chart</h2></div></div></div><p>This example shows a horizontal stacked bar chart.As always, the X axis is horizontal, and the Y axis is vertical.But the data array contains the X value for each implicit Y.The data type 'text-data-yx' indicates this is ahorizontal plot.</p><div class="example"><a id="example-horizstackedbar"></a><p class="title"><strong>Example 5.28. Horizontal Stacked Bar Chart</strong></p><div class="example-contents"><div class="informalfigure"><div class="mediaobject"><img src="examples/horizstackedbar.png" alt="Horizontal Stacked Bar Chart Example" /></div></div><pre class="programlisting"><?php# PHPlot Example - Horizontal Stacked Barsrequire_once 'phplot.php';$column_names = array('Beef', 'Fish', 'Pork', 'Chicken', 'Butter','Cheese','Ice Cream');// | | | | | | |$data = array(array('1910', 48.5, 11.2, 38.2, 11.0, 18.4, 3.9, 1.9),array('1930', 33.7, 10.2, 41.1, 11.1, 17.6, 4.7, 9.7),array('1950', 44.6, 11.9, 43.0, 14.3, 10.9, 7.7, 17.4),array('1970', 79.6, 11.7, 48.1, 27.4, 5.4, 11.4, 17.8),array('1990', 63.9, 14.9, 46.4, 42.4, 4.0, 24.6, 15.8),);$plot = new PHPlot(800, 500);$plot->SetImageBorderType('plain'); // Improves presentation in the manual$plot->SetTitle("U.S. Annual Per-Capita Consumption\n". "of Selected Meat and Dairy Products");$plot->SetLegend($column_names);# Move the legend to the lower right of the plot area:$plot->SetLegendPixels(700, 300);$plot->SetDataValues($data);$plot->SetDataType('text-data-yx');$plot->SetPlotType('stackedbars');$plot->SetXTitle('Pounds Consumed Per Capita');# Show data value labels:$plot->SetXDataLabelPos('plotstack');# Rotate data value labels to 90 degrees:$plot->SetXDataLabelAngle(90);# Format the data value labels with 1 decimal place:$plot->SetXDataLabelType('data', 1);# Specify a whole number for the X tick interval:$plot->SetXTickIncrement(20);# Disable the Y tick marks:$plot->SetYTickPos('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-horizbar.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-horizthinbarline.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.27. Example - Horizontal 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.29. Example - Horizontal Thin Bar Line Plot</td></tr></table></div></body></html>