bar-charts.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Vertical and Horizontal Bar Charts</title>
  5. <link class="include" rel="stylesheet" type="text/css" href="../jquery.jqplot.min.css" />
  6. <link rel="stylesheet" type="text/css" href="examples.min.css" />
  7. <link type="text/css" rel="stylesheet" href="syntaxhighlighter/styles/shCoreDefault.min.css" />
  8. <link type="text/css" rel="stylesheet" href="syntaxhighlighter/styles/shThemejqPlot.min.css" />
  9. <!--[if lt IE 9]><script language="javascript" type="text/javascript" src="../excanvas.js"></script><![endif]-->
  10. <script class="include" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  11. </head>
  12. <body>
  13. <div id="header">
  14. <div class="nav">
  15. <a class="nav" href="../../../index.php"><span>&gt;</span>Home</a>
  16. <a class="nav" href="../../../docs/"><span>&gt;</span>Docs</a>
  17. <a class="nav" href="../../download/"><span>&gt;</span>Download</a>
  18. <a class="nav" href="../../../info.php"><span>&gt;</span>Info</a>
  19. <a class="nav" href="../../../donate.php"><span>&gt;</span>Donate</a>
  20. </div>
  21. </div>
  22. <div class="colmask leftmenu">
  23. <div class="colleft">
  24. <div class="col1" id="example-content">
  25. <!-- Example scripts go here -->
  26. <style type="text/css">
  27. .note {
  28. font-size: 0.8em;
  29. }
  30. .jqplot-yaxis-tick {
  31. white-space: nowrap;
  32. }
  33. </style>
  34. <div id="chart1" style="width:600px; height:250px;"></div>
  35. <pre class="code brush: js"></pre>
  36. <div id="chart2" style="width:400px; height:300px;"></div>
  37. <pre class="code brush: js"></pre>
  38. <p class="text">Click on a bar in the plot below to update the text box.</p>
  39. <p class="text">You Clicked:
  40. <span id="info3">Nothing yet.</span>
  41. </p>
  42. <div id="chart3" style="width:400px; height:300px;"></div>
  43. <pre class="code brush: js"></pre>
  44. <script class="code" type="text/javascript">
  45. $(document).ready(function(){
  46. var s1 = [200, 600, 700, 1000];
  47. var s2 = [460, -210, 690, 820];
  48. var s3 = [-260, -440, 320, 200];
  49. // Can specify a custom tick Array.
  50. // Ticks should match up one for each y value (category) in the series.
  51. var ticks = ['May', 'June', 'July', 'August'];
  52. var plot1 = $.jqplot('chart1', [s1, s2, s3], {
  53. // The "seriesDefaults" option is an options object that will
  54. // be applied to all series in the chart.
  55. seriesDefaults:{
  56. renderer:$.jqplot.BarRenderer,
  57. rendererOptions: {fillToZero: true}
  58. },
  59. // Custom labels for the series are specified with the "label"
  60. // option on the series option. Here a series option object
  61. // is specified for each series.
  62. series:[
  63. {label:'Hotel'},
  64. {label:'Event Regristration'},
  65. {label:'Airfare'}
  66. ],
  67. // Show the legend and put it outside the grid, but inside the
  68. // plot container, shrinking the grid to accomodate the legend.
  69. // A value of "outside" would not shrink the grid and allow
  70. // the legend to overflow the container.
  71. legend: {
  72. show: true,
  73. placement: 'outsideGrid'
  74. },
  75. axes: {
  76. // Use a category axis on the x axis and use our custom ticks.
  77. xaxis: {
  78. renderer: $.jqplot.CategoryAxisRenderer,
  79. ticks: ticks
  80. },
  81. // Pad the y axis just a little so bars can get close to, but
  82. // not touch, the grid boundaries. 1.2 is the default padding.
  83. yaxis: {
  84. pad: 1.05,
  85. tickOptions: {formatString: '$%d'}
  86. }
  87. }
  88. });
  89. });
  90. </script>
  91. <script class="code" type="text/javascript">
  92. $(document).ready(function(){
  93. // For horizontal bar charts, x an y values must will be "flipped"
  94. // from their vertical bar counterpart.
  95. var plot2 = $.jqplot('chart2', [
  96. [[2,1], [4,2], [6,3], [3,4]],
  97. [[5,1], [1,2], [3,3], [4,4]],
  98. [[4,1], [7,2], [1,3], [2,4]]], {
  99. seriesDefaults: {
  100. renderer:$.jqplot.BarRenderer,
  101. // Show point labels to the right ('e'ast) of each bar.
  102. // edgeTolerance of -15 allows labels flow outside the grid
  103. // up to 15 pixels. If they flow out more than that, they
  104. // will be hidden.
  105. pointLabels: { show: true, location: 'e', edgeTolerance: -15 },
  106. // Rotate the bar shadow as if bar is lit from top right.
  107. shadowAngle: 135,
  108. // Here's where we tell the chart it is oriented horizontally.
  109. rendererOptions: {
  110. barDirection: 'horizontal'
  111. }
  112. },
  113. axes: {
  114. yaxis: {
  115. renderer: $.jqplot.CategoryAxisRenderer
  116. }
  117. }
  118. });
  119. });
  120. </script>
  121. <script class="code" type="text/javascript">
  122. $(document).ready(function(){
  123. var s1 = [2, 6, 7, 10];
  124. var s2 = [7, 5, 3, 4];
  125. var s3 = [14, 9, 3, 8];
  126. plot3 = $.jqplot('chart3', [s1, s2, s3], {
  127. // Tell the plot to stack the bars.
  128. stackSeries: true,
  129. captureRightClick: true,
  130. seriesDefaults:{
  131. renderer:$.jqplot.BarRenderer,
  132. rendererOptions: {
  133. // Put a 30 pixel margin between bars.
  134. barMargin: 30,
  135. // Highlight bars when mouse button pressed.
  136. // Disables default highlighting on mouse over.
  137. highlightMouseDown: true
  138. },
  139. pointLabels: {show: true}
  140. },
  141. axes: {
  142. xaxis: {
  143. renderer: $.jqplot.CategoryAxisRenderer
  144. },
  145. yaxis: {
  146. // Don't pad out the bottom of the data range. By default,
  147. // axes scaled as if data extended 10% above and below the
  148. // actual range to prevent data points right on grid boundaries.
  149. // Don't want to do that here.
  150. padMin: 0
  151. }
  152. },
  153. legend: {
  154. show: true,
  155. location: 'e',
  156. placement: 'outside'
  157. }
  158. });
  159. // Bind a listener to the "jqplotDataClick" event. Here, simply change
  160. // the text of the info3 element to show what series and ponit were
  161. // clicked along with the data for that point.
  162. $('#chart3').bind('jqplotDataClick',
  163. function (ev, seriesIndex, pointIndex, data) {
  164. $('#info3').html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data);
  165. }
  166. );
  167. });
  168. </script>
  169. <!-- End example scripts -->
  170. <!-- Don't touch this! -->
  171. <script class="include" type="text/javascript" src="../jquery.jqplot.min.js"></script>
  172. <script type="text/javascript" src="syntaxhighlighter/scripts/shCore.min.js"></script>
  173. <script type="text/javascript" src="syntaxhighlighter/scripts/shBrushJScript.min.js"></script>
  174. <script type="text/javascript" src="syntaxhighlighter/scripts/shBrushXml.min.js"></script>
  175. <!-- End Don't touch this! -->
  176. <!-- Additional plugins go here -->
  177. <script class="include" language="javascript" type="text/javascript" src="../plugins/jqplot.barRenderer.min.js"></script>
  178. <script class="include" language="javascript" type="text/javascript" src="../plugins/jqplot.categoryAxisRenderer.min.js"></script>
  179. <script class="include" language="javascript" type="text/javascript" src="../plugins/jqplot.pointLabels.min.js"></script>
  180. <!-- End additional plugins -->
  181. </div>
  182. <div class="col2">
  183. <div class="example-link"><a class="example-link" href="data-renderers.html">AJAX and JSON Data Loading via Data Renderers</a></div>
  184. <div class="example-link"><a class="example-link" href="barLineAnimated.html">Animated Charts</a></div>
  185. <div class="example-link"><a class="example-link" href="dashboardWidget.html">Animated Dashboard Sample - Filled Line with Log Axis</a></div>
  186. <div class="example-link"><a class="example-link" href="kcp_area.html">Area Chart</a></div>
  187. <div class="example-link"><a class="example-link" href="kcp_area2.html">Area Chart 2</a></div>
  188. <div class="example-link"><a class="example-link" href="axisLabelTests.html">Axis Labels</a></div>
  189. <div class="example-link"><a class="example-link" href="axisLabelsRotatedText.html">Axis Labels and Rotated Text</a></div>
  190. <div class="example-link"><a class="example-link" href="barTest.html">Bar Charts</a></div>
  191. <div class="example-link"><a class="example-link" href="multipleBarColors.html">Bar Colors Example</a></div>
  192. <div class="example-link"><a class="example-link" href="bezierCurve.html">Bezier Curve Plots</a></div>
  193. <div class="example-link"><a class="example-link" href="blockPlot.html">Block Plots</a></div>
  194. <div class="example-link"><a class="example-link" href="bubbleChart.html">Bubble Charts</a></div>
  195. <div class="example-link"><a class="example-link" href="bubble-plots.html">Bubble Plots</a></div>
  196. <div class="example-link"><a class="example-link" href="candlestick.html">Candlestick and Open Hi Low Close Charts</a></div>
  197. <div class="example-link"><a class="example-link" href="theming.html">Chart Theming</a></div>
  198. <div class="example-link"><a class="example-link" href="fillBetweenLines.html">Charts with Fill Between Lines</a></div>
  199. <div class="example-link"><a class="example-link" href="kcp_cdf.html">Cumulative Density Function Chart</a></div>
  200. <div class="example-link"><a class="example-link" href="dashedLines.html">Dashed Lines with Smoothing</a></div>
  201. <div class="example-link"><a class="example-link" href="cursor-highlighter.html">Data Point Highlighting, Tooltips and Cursor Tracking</a></div>
  202. <div class="example-link"><a class="example-link" href="point-labels.html">Data Point labels</a></div>
  203. <div class="example-link"><a class="example-link" href="date-axes.html">Date Axes</a></div>
  204. <div class="example-link"><a class="example-link" href="dateAxisRenderer.html">Date Axes 2</a></div>
  205. <div class="example-link"><a class="example-link" href="rotatedTickLabelsZoom.html">Date Axes, Rotated Labels and Zooming</a></div>
  206. <div class="example-link"><a class="example-link" href="canvas-overlay.html">Draw Lines on Plots - Canvas Overlay</a></div>
  207. <div class="example-link"><a class="example-link" href="draw-rectangles.html">Draw Rectangles on Plots</a></div>
  208. <div class="example-link"><a class="example-link" href="kcp_engel.html">Engel Curves</a></div>
  209. <div class="example-link"><a class="example-link" href="bandedLine.html">Error Bands and Confidence Intervals</a></div>
  210. <div class="example-link"><a class="example-link" href="area.html">Filled (Area) Charts</a></div>
  211. <div class="example-link"><a class="example-link" href="axisScalingForceTickAt.html">Force Plot to Have Tick at 0 or 100</a></div>
  212. <div class="example-link"><a class="example-link" href="hiddenPlotsInTabs.html">Hidden Plots</a></div>
  213. <div class="example-link"><a class="example-link" href="customHighlighterCursorTrendline.html">Highlighting, Dragging Points, Cursor and Trend Lines</a></div>
  214. <div class="example-link"><a class="example-link" href="line-charts.html">Line Charts and Options</a></div>
  215. <div class="example-link"><a class="example-link" href="kcp_lorenz.html">Lorenz Curves</a></div>
  216. <div class="example-link"><a class="example-link" href="mekkoCharts.html">Mekko Charts</a></div>
  217. <div class="example-link"><a class="example-link" href="meterGauge.html">Meter Gauge</a></div>
  218. <div class="example-link"><a class="example-link" href="candlestick-charts.html">Open Hi Low Close and Candlestick Charts</a></div>
  219. <div class="example-link"><a class="example-link" href="pieTest.html">Pie Charts and Options</a></div>
  220. <div class="example-link"><a class="example-link" href="pieTest4.html">Pie Charts and Options 2</a></div>
  221. <div class="example-link"><a class="example-link" href="pie-donut-charts.html">Pie and Donut Charts</a></div>
  222. <div class="example-link"><a class="example-link" href="selectorSyntax.html">Plot Creation with jQuery Selectors</a></div>
  223. <div class="example-link"><a class="example-link" href="zooming.html">Plot Zooming and Cursor Control</a></div>
  224. <div class="example-link"><a class="example-link" href="kcp_pdf.html">Probability Density Function Chart</a></div>
  225. <div class="example-link"><a class="example-link" href="kcp_pyramid_by_age.html">Pyramid Chart By Age</a></div>
  226. <div class="example-link"><a class="example-link" href="kcp_pyramid.html">Pyramid Charts</a></div>
  227. <div class="example-link"><a class="example-link" href="kcp_pyramid2.html">Pyramid Charts 2</a></div>
  228. <div class="example-link"><a class="example-link" href="kcp_quintiles.html">Quintile Pyramid Charts</a></div>
  229. <div class="example-link"><a class="example-link" href="resizablePlot.html">Resizable Plots</a></div>
  230. <div class="example-link"><a class="example-link" href="rotated-tick-labels.html">Rotated Labels and Font Styling</a></div>
  231. <div class="example-link"><a class="example-link" href="smoothedLine.html">Smoothed Lines</a></div>
  232. <div class="example-link"><a class="example-link" href="bar-charts.html">Vertical and Horizontal Bar Charts</a></div>
  233. <div class="example-link"><a class="example-link" href="waterfall.html">Waterfall Charts</a></div>
  234. <div class="example-link"><a class="example-link" href="waterfall2.html">Waterfall Charts 2</a></div>
  235. <div class="example-link"><a class="example-link" href="zoomOptions.html">Zoom Options</a></div>
  236. <div class="example-link"><a class="example-link" href="zoomProxy.html">Zoom Proxy - Control one plot from another</a></div>
  237. <div class="example-link"><a class="example-link" href="zoom1.html">Zooming</a></div>
  238. <div class="example-link"><a class="example-link" href="dateAxisLogAxisZooming.html">Zooming with Date and Log Axes</a></div>
  239. </div>
  240. </div>
  241. </div>
  242. <script type="text/javascript" src="example.min.js"></script>
  243. </body>
  244. </html>