单堆叠水平条形图插件 jQuery条形图

  • 源码大小:11.04KB
  • 所需积分:1积分
  • 源码编号:19JP-3696
  • 浏览次数:994次
  • 最后更新:2023年07月12日
  • 所属栏目:图表
本站默认解压密码:19jp.com 或 19jp_com

简介

条形图是以图形方式显示数据的最常见方式之一。它很容易阅读,对数据集进行了快速而全面的概述。

在本文中,我将向您介绍一个名为barChat的全新插件,该插件可用于从JS数组中定义的数据集创建单个或堆叠的水平条形图。玩得高兴

如何使用它:

1.创建一个容器来容纳条形图。

  1. <div class="chart" id="graph">
  2. </div>

2.在JS对象数组中定义您的数据,如下所示:

  1. // single bar chart
  2. const myData = [
  3. {
  4. 'value': [17],
  5. 'color' :[], // bar colors
  6. 'labelColor' :['black'],
  7. 'barLabel': 'Label 1'
  8. },
  9. // ... more data here
  10. ];
  11.  
  12. // stacked bar chart
  13. const myData = [
  14. {
  15. 'value': [17,1,3],
  16. 'color' :['red','yellow','green'],
  17. 'labelColor' :['black'],
  18. 'barLabel': 'Label 1'
  19. },
  20. // ... more data here
  21. ];

3.在jQuery之后加载barGraph.js。

  1. <script src="/path/to/cdn/jquery.slim.min.js"></script>
  2. <script src="/path/to/barGraph.js"></script>

4.使用以下选项自定义条形图。

  1. const myOptions = {
  2. // in pixels
  3. width: 500,
  4. height: 300,
  5. barSpacing: 4,
  6. graphFont: 16,
  7. // bottom, center, top
  8. barLabelPosition: 'center',
  9. yLableColor: 'green',
  10. backgroundBarColor: 'rgb(100,255,255)',
  11. titleFont: {size: 24, color: "black"},
  12. title: "Saying Thanks!",
  13. xAxisTitle: 'Average thank you\'s per day',
  14. xAxisTitleFont: {size: 24, color: "black"},
  15. // max value
  16. xMax: 60,
  17. // tick steps
  18. xsteps: 6
  19. };

5.初始化插件,并从您提供的数据集中绘制一个水平条形图。

  1. let myChart = $("#graph");
  2. drawBarChart(myData, myOptions, myChart);

预览截图