当前位置:   article > 正文

Web开发:小结Apache Echarts官网上常用的配置项(前端可视化图表)

Web开发:小结Apache Echarts官网上常用的配置项(前端可视化图表)

目录

一、须知

二、Title

三、 Legend

四、Grid


一、须知

配置项官方文档:点此进入

我总结了比较常用的功能,写进注释里面,附带链接分享和效果图展示。(更新中....)

二、Title

  1. option = {
  2. title: {
  3. text: 'Weekly Sales',//标题文本
  4. textStyle: {
  5. color: '#333', // 标题文本颜色
  6. fontWeight: 'bold', // 标题文本字体粗细,可选'normal','bold','bolder','lighter'
  7. fontSize: 18, // 标题文本字体大小
  8. },
  9. subtext: 'Unit: Pieces', // 副标题文本内容
  10. subtextStyle: {
  11. color: '#aaa', // 副标题文本颜色
  12. fontStyle: 'normal', // 副标题文本字体风格
  13. fontWeight: 'normal', // 副标题文本字体粗细
  14. fontSize: 14 // 副标题文本字体大小
  15. },
  16. textAlign: 'auto', // 标题文本水平对齐方式,可选值:'auto'、'left'、'right'、'center'
  17. padding: [10, 10, 10, 10], // 标题的内边距,上右下左
  18. itemGap: 10, // 主副标题之间的间距
  19. left: 'center', // 标题组件离容器左侧的距离,可选'left', 'center', 'right',20,'20%'
  20. top:'top' // 标题组件离容器顶部的距离,可选'top', 'middle', 'bottom',20,'20%'
  21. },
  22. xAxis: {
  23. type: 'category',
  24. data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  25. },
  26. yAxis: {
  27. type: 'value'
  28. },
  29. series: [
  30. {
  31. data: [150, 230, 224, 218, 135, 147, 260],
  32. type: 'line'
  33. }
  34. ]
  35. };

【分享链接:点此进入

【实现效果】

三、 Legend

  1. option = {
  2. title: {
  3. text: 'Referer of a Website',
  4. left: 'center'
  5. },
  6. tooltip: {
  7. trigger: 'item', // 提示框触发类型为数据项触发
  8. formatter: '{a} <br/>{b} : {c} ({d}%)' // 提示框内容格式器:显示series的name、data的name、data的value和百分比
  9. },
  10. legend: {
  11. orient: 'vertical', // 图例布局方式为垂直,可选'horizontal','vertical'
  12. left: 'left', // 图例组件离容器左侧的距离,可选'left', 'center', 'right'
  13. itemHeight: 14, // 图例的高
  14. itemWidth: 14, // 图例的宽
  15. itemGap: 20, // 图例之间的间隔
  16. padding: [40, 20, 10, 5], // 上、右、下、左的内边距(移动位置)
  17. textStyle: {
  18. color: '#333', // 图例文字颜色
  19. fontSize: 12 // 图例文字大小
  20. },
  21. data: ['Search Engine', 'Direct', 'Email', 'Union Ads', 'Video Ads'] // 图例数据,与series中的name对应
  22. },
  23. series: [
  24. {
  25. name: 'Access From',
  26. type: 'pie', // 图表类型为饼图
  27. radius: '50%', // 饼图半径,可设置为相对的百分比或绝对的像素值
  28. center: ['50%', '60%'], // 饼图的中心(圆心)坐标,支持绝对像素和相对百分比
  29. data: [
  30. { value: 1048, name: 'Search Engine' },
  31. { value: 735, name: 'Direct' },
  32. { value: 580, name: 'Email' },
  33. { value: 484, name: 'Union Ads' },
  34. { value: 300, name: 'Video Ads' }
  35. ],
  36. label: {
  37. show: true, // 是否显示标签
  38. formatter: '{b} : {c} ({d}%)', // 显示data的name、data的value和百分比
  39. fontSize: 12 // 标签文字大小
  40. },
  41. labelLine: {
  42. show: true // 是否显示标签的视觉引导线
  43. },
  44. emphasis: {//鼠标悬浮阴影
  45. itemStyle: {
  46. shadowBlur: 10,
  47. shadowOffsetX: 10,
  48. shadowColor: 'rgba(0, 0, 0, 0.5)'
  49. }
  50. },
  51. animationType: 'scale', // 数据更新动画的类型
  52. animationEasing: 'elasticOut', // 数据更新动画的缓动效果
  53. animationDelay: function (idx) { // 数据更新动画的延迟
  54. return idx * 50;
  55. }
  56. }
  57. ]
  58. };

分享链接

【实现效果】

四、Grid

  1. option = {
  2. grid: {
  3. show: true,
  4. left: '10%', // 网格左边距
  5. top: 60, // 网格顶边距
  6. borderWidth: 1 // 网格边框宽度
  7. },
  8. xAxis: {
  9. type: 'category',
  10. data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  11. },
  12. yAxis: {
  13. type: 'value'
  14. },
  15. tooltip: {
  16. show: true, // 显示提示框
  17. trigger: 'axis', // 触发类型,鼠标悬停显示提示框
  18. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  19. type: 'line' // 指示器类型为直线
  20. }
  21. },
  22. series: [
  23. {
  24. data: [820, 932, 901, 934, 1290, 1330, 1320],
  25. type: 'line',
  26. smooth: true
  27. }
  28. ]
  29. };

实现链接】 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/918519
推荐阅读
相关标签
  

闽ICP备14008679号