- Learning jqPlot
- Scott Gottreu
- 486字
- 2021-09-03 09:49:45
Building bars of data
While at lunch, Calvin took several phone calls. One near the end of lunch was from Sara, VP of Inventory. Her department is facing issues with higher than normal returns. She has a team investigating the problem, but she wants help. She wants a chart showing how much money is lost to returns and the reasons for the returns. She'd like the charts by the end of the meeting on Friday so that she can present the problem to the whole team. She needs their buy-in and help to work toward a solution.
Calvin relays this information to us as we walk back to the office. "She said she was going to e-mail a spreadsheet with the past six months' data in it. Can you do your thing and make Sara look like a rockstar? Her department is the most ignored, but it's the backbone of the company." We tell him we'll do our best.
By the time we get back to our desks, we have an e-mail waiting for us. We open the spreadsheet and see the following data:

After looking over the data, we decide that our best choice is a bar chart. Bar charts are best used when we have categorical data to compare. We can compare various data points in one series or multiple data series. With this chart, we will be able to compare the dollar amounts in each category listed previously, so we will have just one data series. It is also possible to have multiple data series in each category, such as a different bar for each product category, and these data series grouped by regions.
- We start by including the
categoryAxisRenderer
andbarRenderer
plugins. These extend jqPlot to allow us to group our x axis by categories and create a bar chart:<script src="../js/jqplot.categoryAxisRenderer.min.js"></script> <script src="../js/jqplot.barRenderer.min.js"></script> <script> $(document).ready(function(){
- We include our array containing the data points. Since we are using
categoryAxisRenderer
, we pass a string as thex
value instead of a number or date:var returns = [['Damaged Item', 15876.98], ['Defective Item', 26078.41], ['Gift', 6397.06], ['Not Correct Item', 12876.60]]; var product_returns = $.jqplot ('product_returns', [returns], { title:'Total Cost of Product Returns over 6 months',
- We assign
BarRenderer
to therenderer
option for our one data series. If we were to include multiple data series, we could include this inseriesDefaults
so we'd only have to include it once:series: [ { renderer:$.jqplot.BarRenderer } ],
- Since we are using categories for the x axis, we need to enable
CategoryAxisRenderer
as the renderer for the x axis:axes:{ xaxis:{ renderer: $.jqplot.CategoryAxisRenderer }, yaxis: { label: 'Totals Dollars', tickOptions: { formatString: "$%'d" } } } }); }); </script> <div id="product_returns" style="width:600px;"></div>
Tip
We can mix and match data renderers. If we had multiple data series, we could render a bar chart for the first series and use a line chart for the second.
We load the page in our browser and see the following result:

- Oracle BAM 11gR1 Handbook
- Mastering Android Development with Kotlin
- C++面向對象程序設計習題解答與上機指導(第三版)
- PLC應用技術(三菱FX2N系列)
- 微服務架構深度解析:原理、實踐與進階
- 動手學數據結構與算法
- 速學Python:程序設計從入門到進階
- 軟件體系結構
- Application Development with Parse using iOS SDK
- 3D Printing Designs:The Sun Puzzle
- Beginning C# 7 Hands-On:The Core Language
- Go語言編程之旅:一起用Go做項目
- Learning Rust
- 數據預處理從入門到實戰:基于SQL、R、Python
- 計算機視覺增強現實應用程序開發