jQuery 吸引人 绘图插件 Flot

  • 源码大小:1.12MB
  • 所需积分:1积分
  • 源码编号:19JP-3219
  • 浏览次数:699次
  • 最后更新:2023年05月19日
  • 所属栏目:图表
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

Flot是一个JavaScript绘图库,与jQuery一起使用HTML5画布元素生成动态、有吸引力和交互式的图表。

您可能还喜欢jQuery Flot Animator插件来为您的Flot图表设置动画。

安装和下载:

  1. # NPM
  2. $ npm install flot --save

基本用法:

1.在页面上包含jQuery和Flot.js JavaScript库。

  1. <script src="/path/to/jquery.js"></script>
  2. <script src="/path/to/jquery.flot.js"></script>
  3. <!--[if lte IE 8]>
  4. <script src="/path/to/excanvas.min.js"></script>
  5. <![endif]-->

2.为图表创建占位符元素。

  1. <div id="placeholder"></div>

3.准备好要绘制在图表中的数据。

  1. var data = [ ["January", 10], ["February", 8], ["March", 4], ["April", 13], ["May", 17], ["June", 9]];

4.根据数据数组生成一个基本折线图。

  1. $.plot("#placeholder", data);

5.自定义图表的所有默认选项。

  1. $.plot("#placeholder", data,{
  2. // the color theme used for graphs
  3. colors: ["#edc240", "#afd8f8", "#cb4b4b", "#4da74d", "#9440ed"],
  4. xaxis: {
  5. show: null, // null = auto-detect, true = always, false = never
  6. position: "bottom", // or "top"
  7. mode: null, // null or "time"
  8. font: null, // null (derived from CSS in placeholder) or object like { size: 11, lineHeight: 13, style: "italic", weight: "bold", family: "sans-serif", variant: "small-caps" }
  9. color: null, // base color, labels, ticks
  10. tickColor: null, // possibly different color of ticks, e.g. "rgba(0,0,0,0.15)"
  11. transform: null, // null or f: number -> number to transform axis
  12. inverseTransform: null, // if transform is set, this should be the inverse function
  13. min: null, // min. value to show, null means set automatically
  14. max: null, // max. value to show, null means set automatically
  15. autoScaleMargin: null, // margin in % to add if autoScale option is on "loose" mode,
  16. autoScale: "exact", // Available modes: "none", "loose", "exact", "sliding-window"
  17. windowSize: null, // null or number. This is the size of sliding-window.
  18. growOnly: null, // grow only, useful for smoother auto-scale, the scales will grow to accomodate data but won't shrink back.
  19. ticks: null, // either [1, 3] or [[1, "a"], 3] or (fn: axis info -> ticks) or app. number of ticks for auto-ticks
  20. tickFormatter: null, // fn: number -> string
  21. showTickLabels: "major", // "none", "endpoints", "major", "all"
  22. labelWidth: null, // size of tick labels in pixels
  23. labelHeight: null,
  24. reserveSpace: null, // whether to reserve space even if axis isn't shown
  25. tickLength: null, // size in pixels of major tick marks
  26. showMinorTicks: null, // true = show minor tick marks, false = hide minor tick marks
  27. showTicks: null, // true = show tick marks, false = hide all tick marks
  28. gridLines: null, // true = show grid lines, false = hide grid lines
  29. alignTicksWithAxis: null, // axis number or null for no sync
  30. tickDecimals: null, // no. of decimals, null means auto
  31. tickSize: null, // number or [number, "unit"]
  32. minTickSize: null, // number or [number, "unit"]
  33. offset: { below: 0, above: 0 }, // the plot drawing offset. this is calculated by the flot.navigate for each axis
  34. boxPosition: { centerX: 0, centerY: 0 } //position of the axis on the corresponding axis box
  35. },
  36. yaxis: {
  37. autoScaleMargin: 0.02, // margin in % to add if autoScale option is on "loose" mode
  38. autoScale: "loose", // Available modes: "none", "loose", "exact"
  39. growOnly: null, // grow only, useful for smoother auto-scale, the scales will grow to accomodate data but won't shrink back.
  40. position: "left", // or "right"
  41. showTickLabels: "major", // "none", "endpoints", "major", "all"
  42. offset: { below: 0, above: 0 }, // the plot drawing offset. this is calculated by the flot.navigate for each axis
  43. boxPosition: { centerX: 0, centerY: 0 } //position of the axis on the corresponding axis box
  44. },
  45.  
  46. // if you need more than one x axis or y axis
  47. xaxes: [],
  48. yaxes: [],
  49.  
  50. // customize the data series
  51. series: {
  52. points: {
  53. show: false,
  54. radius: 3,
  55. lineWidth: 2, // in pixels
  56. fill: true,
  57. fillColor: "#ffffff",
  58. symbol: 'circle' // or callback
  59. },
  60. lines: {
  61. // we don't put in show: false so we can see
  62. // whether lines were actively disabled
  63. lineWidth: 1, // in pixels
  64. fill: false,
  65. fillColor: null,
  66. steps: false
  67. // Omit 'zero', so we can later default its value to
  68. // match that of the 'fill' option.
  69. },
  70. bars: {
  71. show: false,
  72. lineWidth: 2, // in pixels
  73. // barWidth: number or [number, absolute]
  74. // when 'absolute' is false, 'number' is relative to the minimum distance between points for the series
  75. // when 'absolute' is true, 'number' is considered to be in units of the x-axis
  76. horizontal: false,
  77. barWidth: 0.8,
  78. fill: true,
  79. fillColor: null,
  80. align: "left", // "left", "right", or "center"
  81. zero: true
  82. },
  83. shadowSize: 3,
  84. highlightColor: null
  85. },
  86. grid: {
  87. show: true,
  88. aboveData: false,
  89. color: "#545454", // primary color used for outline and labels
  90. backgroundColor: null, // null for transparent, else color
  91. borderColor: null, // set if different from the grid color
  92. tickColor: null, // color for the ticks, e.g. "rgba(0,0,0,0.15)"
  93. margin: 0, // distance from the canvas edge to the grid
  94. labelMargin: 5, // in pixels
  95. axisMargin: 8, // in pixels
  96. borderWidth: 1, // in pixels
  97. minBorderMargin: null, // in pixels, null means taken from points radius
  98. markings: null, // array of ranges or fn: axes -> array of ranges
  99. markingsColor: "#f4f4f4",
  100. markingsLineWidth: 2,
  101. // interactive stuff
  102. clickable: false,
  103. hoverable: false,
  104. autoHighlight: true, // highlight in case mouse is near
  105. mouseActiveRadius: 15 // how far the mouse can be away to activate an item
  106. },
  107. interaction: {
  108. redrawOverlayInterval: 1000 / 60 // time between updates, -1 means in same flow
  109. },
  110. hooks: {}
  111. });

更新日志:

版本4.2.4(2023-01-21)

  • 修复了步骤渲染不将最后一点与线连接的问题

v4.2.2 (2021-03-17)

  • 解决水平条系列计算自动缩放范围的问题

版本4.2.1(2020-05-07)

  • 修复了在水平条形图上显示y轴端点记号的问题

版本4.2.0(2020-02-05)

  • 使现代化

第4.1.1版(2019-11-22)

  • 清除鼠标离开时饼图悬停高亮显示。

第4.1.0版(2019-11-06)

  • 引入新的钩子,允许用户扩展flot提供的findNearbyItems方法的默认行为。

版本4.0.0(2019-10-30)

  • 创建一个新的主要版本,因为我们引入了一个更改,需要包含一个新脚本来保持正确的行为。这将取代从3.2.11开始发布的先前补丁。这也有一个小错误修复,用于修复条形图的悬停问题。

版本3.2.13(2019-10-16)

  • 修复了微秒日期上毫秒值不一致的问题

版本3.2.12(2019-10-15)

  • 对选择插件进行了小修复,以删除不需要的行。

版本3.2.11(2019-10-15)

  • 修复了选择插件与其他使用拖动事件的插件一起使用的问题,即我们无法从单独插件的拖动处理程序中正确禁用选择插件拖动处理程序。

版本3.2.10(2019-09-25)

  • 制定本地声明

第3.2.9版(2019-08-22)

  • 同时为setData和重做绘图工作

第3.2.8版(2019-08-21)

  • 修复重置时的移动

第3.2.7版(2019-08-09)

  • 修复最近更改悬停插件后损坏的分发。

第3.2.5版(2019-08-02)

  • 在数据中遇到NaN时,在绘图的线条渲染中引入间隙。

第3.2.4版(2019-07-30)

  • 该插件现在捕获从CORS对样式表的请求中抛出的异常,以允许继续执行。发生这种情况时,它会在控制台中报告该问题。

第3.2.3版(2019年7月19日)

  • 将选择模式设置为“null”将立即将其关闭。

第3.2.2版(2019-06-29)

  • 修复优化更改结果的问题

v3.2.1(2019年6月27日)

  • 修正了即使在没有数据的情况下,当轴autoScale设置为“松散”时,范围捕捉到值的问题

v3.2.0(2019年6月19日)

  • 正在恢复加载CORS样式表的更改。
  • 各种错误修复。

v3.1.1(2019年6月14日)

  • 修复Safari上加载跨域样式表的问题。

v3.1.0(2019年5月31日)

  • 引入第二个事件,当绘制完成时,源于placeHolder
  • 修复了在跨域上下文中样式表不起作用的问题
  • 修复了新版Chrome引入的Math.pow()问题。

3.0.0版(2019年4月3日)

  • 修复悬停插件中的内存泄漏。

版本3.0.0(2019-03-23)

  • 更改:设置平移:{enableTouch:true}将不再自动打开用于触摸支持的捏手势。现在可以通过设置缩放来打开捏手势:{enableTouch:true}。现在可以选择性地关闭重新居中的双击(或点击)机制。最后,我们提供了一个选项,允许事件为导航插件处理的手势传播,无论它们是否启用。

v2.3.2版本(2019-03-22)

  • 修复了扩展Date类导致babel出现问题的问题。

v2.3.1版本(2019-03-21)

  • 添加微秒作为轴的timeBase设置选项。各种错误修复。
  • 修复了从缩小的源代码中使用悬停插件时的错误。

v2.2.1版本(2019-03-05)

  • 为鼠标和触摸交互添加了新的平移模式。

v2.2.0版本(2019-02-27)

  • 为鼠标和触摸交互添加了新的平移模式。
  • 修复了空字符串刻度标签被自动生成的标签替换的问题。
  • 修正了悬停在条形图上不再工作的问题。
  • 修复了再次更新图例的跟踪示例。
  • 修复了堆叠图形的工具提示不正确的问题。

v2.1.6版本(2019-02-12)

  • 更新到最新版本。

预览截图