6 <title>Vertical and Horizontal Bar Charts
</title>
8 <link class=
"include" rel=
"stylesheet" type=
"text/css" href=
"../jquery.jqplot.min.css" />
9 <link rel=
"stylesheet" type=
"text/css" href=
"examples.min.css" />
10 <link type=
"text/css" rel=
"stylesheet" href=
"syntaxhighlighter/styles/shCoreDefault.min.css" />
11 <link type=
"text/css" rel=
"stylesheet" href=
"syntaxhighlighter/styles/shThemejqPlot.min.css" />
13 <!--[if lt IE 9]><script language="javascript" type="text/javascript" src="../excanvas.js"></script><![endif]-->
14 <script class="include" type="text/javascript" src="../jquery.min.js"></script>
21 <a class="nav" href="../../../index.php"><span>></span>Home</a>
22 <a class="nav" href="../../../docs/"><span>></span>Docs</a>
23 <a class="nav" href="../../download/"><span>></span>Download</a>
24 <a class="nav" href="../../../info.php"><span>></span>Info</a>
25 <a class="nav" href="../../../donate.php"><span>></span>Donate</a>
28 <div class="example-content">
30 <div class="example-nav">
31 <a href="bandedLine.html">Previous</a> <a href="./">Examples</a> <a href="barLineAnimated.html">Next</a></div>
34 <!-- Example scripts go here -->
37 <style type="text/css">
47 <div id="chart1" style="width:600px; height:250px;"></div>
49 <pre class="code brush: js"></pre>
51 <div id="chart2" style="width:400px; height:300px;"></div>
53 <pre class="code brush: js"></pre>
55 <p class="text">Click on a bar in the plot below to update the text box.</p>
56 <p class="text">You Clicked:
57 <span id="info3">Nothing yet.</span>
59 <div id="chart3" style="width:400px; height:300px;"></div>
61 <pre class="code brush: js"></pre>
63 <script class="code" type="text/javascript">
64 $(document).ready(function(){
65 var s1 = [200, 600, 700, 1000];
66 var s2 = [460, -210, 690, 820];
67 var s3 = [-260, -440, 320, 200];
68 // Can specify a custom tick Array.
69 // Ticks should match up one for each y value (category) in the series.
70 var ticks = ['May', 'June', 'July', 'August'];
72 var plot1 = $.jqplot('chart1', [s1, s2, s3], {
73 // The "seriesDefaults" option is an options object that will
74 // be applied to all series in the chart.
76 renderer:$.jqplot.BarRenderer,
77 rendererOptions: {fillToZero: true}
79 // Custom labels for the series are specified with the "label"
80 // option on the series option. Here a series option object
81 // is specified for each series.
84 {label:'Event Regristration'},
87 // Show the legend and put it outside the grid, but inside the
88 // plot container, shrinking the grid to accomodate the legend.
89 // A value of "outside" would not shrink the grid and allow
90 // the legend to overflow the container.
93 placement: 'outsideGrid'
96 // Use a category axis on the x axis and use our custom ticks.
98 renderer: $.jqplot.CategoryAxisRenderer,
101 // Pad the y axis just a little so bars can get close to, but
102 // not touch, the grid boundaries. 1.2 is the default padding.
105 tickOptions: {formatString: '$%d'}
113 <script class="code" type="text/javascript">
114 $(document).ready(function(){
115 // For horizontal bar charts, x an y values must will be "flipped"
116 // from their vertical bar counterpart.
117 var plot2 = $.jqplot('chart2', [
118 [[2,1], [4,2], [6,3], [3,4]],
119 [[5,1], [1,2], [3,3], [4,4]],
120 [[4,1], [7,2], [1,3], [2,4]]], {
122 renderer:$.jqplot.BarRenderer,
123 // Show point labels to the right ('e'ast) of each bar.
124 // edgeTolerance of -15 allows labels flow outside the grid
125 // up to 15 pixels. If they flow out more than that, they
127 pointLabels: { show: true, location: 'e', edgeTolerance: -15 },
128 // Rotate the bar shadow as if bar is lit from top right.
130 // Here's where we tell the chart it is oriented horizontally.
132 barDirection: 'horizontal'
137 renderer: $.jqplot.CategoryAxisRenderer
144 <script class="code" type="text/javascript">
145 $(document).ready(function(){
146 var s1 = [2, 6, 7, 10];
147 var s2 = [7, 5, 3, 4];
148 var s3 = [14, 9, 3, 8];
149 plot3 = $.jqplot('chart3', [s1, s2, s3], {
150 // Tell the plot to stack the bars.
152 captureRightClick: true,
154 renderer:$.jqplot.BarRenderer,
156 // Put a 30 pixel margin between bars.
158 // Highlight bars when mouse button pressed.
159 // Disables default highlighting on mouse over.
160 highlightMouseDown: true
162 pointLabels: {show: true}
166 renderer: $.jqplot.CategoryAxisRenderer
169 // Don't pad out the bottom of the data range. By default,
170 // axes scaled as if data extended 10% above and below the
171 // actual range to prevent data points right on grid boundaries.
172 // Don't want to do that here.
182 // Bind a listener to the "jqplotDataClick" event. Here, simply change
183 // the text of the info3 element to show what series and ponit were
184 // clicked along with the data for that point.
185 $('#chart3').bind('jqplotDataClick',
186 function (ev, seriesIndex, pointIndex, data) {
187 $('#info3').html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data);
193 <!-- End example scripts -->
195 <!-- Don't touch this! -->
198 <script class="include" type="text/javascript" src="../jquery.jqplot.min.js"></script>
199 <script type="text/javascript" src="syntaxhighlighter/scripts/shCore.min.js"></script>
200 <script type="text/javascript" src="syntaxhighlighter/scripts/shBrushJScript.min.js"></script>
201 <script type="text/javascript" src="syntaxhighlighter/scripts/shBrushXml.min.js"></script>
202 <!-- End Don't touch this! -->
204 <!-- Additional plugins go here -->
206 <script class="include" language="javascript" type="text/javascript" src="../plugins/jqplot.barRenderer.min.js"></script>
207 <script class="include" language="javascript" type="text/javascript" src="../plugins/jqplot.categoryAxisRenderer.min.js"></script>
208 <script class="include" language="javascript" type="text/javascript" src="../plugins/jqplot.pointLabels.min.js"></script>
210 <!-- End additional plugins -->
214 <script type="text/javascript" src="example.min.js"></script>