Blame | Letzte Änderung | Log anzeigen | RSS feed
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso-iso-8859-1"><LINK REL="Start" HREF="index.html"><LINK REL="Contents" HREF="toc.html"><LINK REL="Prev" HREF="7117Addingplotmarkstoalineplot.html"><LINK REL="Next" HREF="721Adjustingthewidthofthebars.html"><STYLE TYPE="text/css"><!--BODY { font-family: serif }H1 { font-family: sans-serif }H2 { font-family: sans-serif }H3 { font-family: sans-serif }H4 { font-family: sans-serif }H5 { font-family: sans-serif }H6 { font-family: sans-serif }SUB { font-size: smaller }SUP { font-size: smaller }PRE { font-family: monospace }A { text-decoration: none }--></STYLE></HEAD><BODY><A HREF="toc.html">Contents</A><A HREF="7117Addingplotmarkstoalineplot.html">Previous</A><A HREF="721Adjustingthewidthofthebars.html">Next</A><HR NOSHADE><H2><A NAME="7_2">7.2 Bar graphs</A></H2><P> Jpgraph also supports 2D vertical bar plots. Before you can use anybar plots you must make sure that you included the file"jpgraph_bar.php" in your script.</P><P> Using bar plots is quite straightforward and works in much the sameway as line plots which you are already familiar with from the previousexamples. Assuming you have a data array consisting of the values[12,8,19,3,10,5] and you want to display them as a bar plot. This isthe simplest way to do this:<DIV class="phpscript"><CODE><FONT color="#000000"><FONT color="#0000BB"> $datay</FONT><FONT color="#007700">=array(</FONT><FONTcolor="#0000BB">12</FONT><FONT color="#007700">,</FONT><FONT color="#0000BB">8</FONT><FONT color="#007700">,</FONT><FONT color="#0000BB">19</FONT><FONTcolor="#007700">,</FONT><FONT color="#0000BB">3</FONT><FONT color="#007700">,</FONT><FONT color="#0000BB">10</FONT><FONT color="#007700">,</FONT><FONTcolor="#0000BB">5</FONT><FONT color="#007700">);<BR></FONT><FONT color="#0000BB">$bplot </FONT><FONT color="#007700">= new </FONT><FONT color="#0000BB">BarPlot</FONT><FONT color="#007700">(</FONT><FONTcolor="#0000BB">$datay</FONT><FONT color="#007700">);<BR></FONT><FONT color="#0000BB">$graph</FONT><FONT color="#007700">-></FONT><FONTcolor="#0000BB">Add</FONT><FONT color="#007700">(</FONT><FONT color="#0000BB">$bplot</FONT><FONT color="#007700">);</FONT><FONT color="#0000BB"></FONT></FONT></CODE></DIV></P><P> If you compare this to the previous line examples you can see thatthe only change necessary was that instead of creating a new line plot(via the new LinePlot(...) call) we used the statement new <A href="../ref/BarPlot.html#_C_BARPLOT">BarPplot().</A></P><P> The other change we should do is to make sure the X-axis have antext-scale (it is perfectly fine to use a linear X-scale but in mostcases this is not the effect you want when you use a bar graph, seemore below). With this two simple change we will now get a bar graph asdisplayed in the following image<DIV class="example"><BR> <A href="exframes/frame_example18.html" target="blank"><IMG border="0"HEIGHT="200" src="img/img/img/img/img/img/example18.png" WIDTH="300"></A><BR><B>Figure 31:</B> A very simple bar graph <A href="exframes/frame_example18.html"target="blank">[src]</A> <P></P></DIV></P><P> You can of course modify the appearance of the bar graph. So forexample to change the fill color you would use the <A href="../ref/BarPlot.html#_BARPLOT_SETFILLCOLOR">BarPlot::SetFillColor()</A> method. Making this small change to theprevious example would give the expected effect as can be seen in thenext example.<DIV class="example"><BR> <A href="exframes/frame_example19.html" target="blank"><IMG border="0"HEIGHT="200" src="img/img/img/img/img/img/example19.png" WIDTH="300"></A><BR><B>Figure 32:</B> A very simple bar graph with changed fill color <A href="exframes/frame_example19.html"target="blank">[src]</A> <P></P></DIV></P><P><DIV class="note"><B>Note:</B> You should note from the previous twographs that slight change in appearance for the X-scale. The bar graphsgets automatically centered between the tick marks when using as textx-scale. If you were to use a linear scale they would instead start atthe left edge of the X-axis and the X-axis would be labeled with alinear scale. As is illustrated in the (small) example below.</DIV><DIV class="example"><BR> <A href="exframes/frame_example19.1.html" target="blank"><IMG border="0"HEIGHT="100" src="img/img/img/img/img/img/example19.1.png" WIDTH="260"></A><BR><B>Figure 33:</B> A small example with a bar graph using a linearX-scale <A href="exframes/frame_example19.1.html" target="blank">[src]</A> <P></P></DIV></P><P></P><HR NOSHADE><A HREF="toc.html">Contents</A><A HREF="7117Addingplotmarkstoalineplot.html">Previous</A><A HREF="721Adjustingthewidthofthebars.html">Next</A></BODY></HTML>