• 使用Apache ECharts同时绘制多个统计图表


    目录

    1、介绍

    2、相关知识

    3、代码

    4、效果


    🍃作者介绍:双非本科大三网络工程专业在读,阿里云专家博主,专注于Java领域学习,擅长web应用开发、数据结构和算法,初步涉猎Python人工智能开发和前端开发。
    🦅主页:@逐梦苍穹

    🍔所属专栏:前端

    📕您的一键三连,是我创作的最大动力🌹

    1、介绍

    echarts是一个比较好用的表格展示。通过不同的配置,就可以实现饼图,柱图以及折线图等。
    方便数据展示。下面就是在同一个页面,通过配置文件创建四个表格的例子。

    2、相关知识

    Apache ECharts:Apache ECharts | 一个数据可视化图表库

    3、代码

    1. html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8" />
    5. <title>EChartstitle>
    6. <script src="echarts.js">script>
    7. head>
    8. <body>
    9. <div id="main" style="width: 1800px;height:900px;">div>
    10. <script type="text/javascript">
    11. // 基于准备好的dom,初始化echarts实例
    12. var myChart = echarts.init(document.getElementById('main'));
    13. // 指定图表的配置项和数据
    14. var option = {
    15. title: [ // 指定各个表格的标题
    16. {text: '销售额', top: '5%', left: '30%'},
    17. {text: '订单量', top: '5%', left: '75%'},
    18. {text: '客单价', left: '30%', top: '50%'},
    19. {text: '动销率', left: '75%', top: '50%',},
    20. ],
    21. dataset: { // 指定数据源
    22. source:
    23. [
    24. ['type','销售额', '订单量', '客单价', '动销率'],
    25. ].concat(
    26. [
    27. ['2019-01-01',100.0,20,4,30],
    28. ['2019-01-02',110.0,21,5,30],
    29. ['2019-01-03',120.0,22,6,30],
    30. ['2019-01-04',140.0,23,7,30],
    31. ['2019-01-05',150.0,24,8,30],
    32. ['2019-01-06',160.0,25,9,30],
    33. ]
    34. )
    35. },
    36. grid: [ // 用来调整,各个表格的位置
    37. {top: '10%', bottom: '55%', width: '40%'},
    38. {top: '10%', bottom: '55%',left: '55%', width: '40%'},
    39. {top: '55%', width: '40%'},
    40. {top: '55%', left: '55%', width: '40%'},
    41. ],
    42. tooltip: {},
    43. legend: {},
    44. xAxis: [ // 用来配置横坐标的信息,gridIndex是标识针对的那个表格
    45. {type: 'category', gridIndex: 0, name: '日期', axisTick: {alignWithLabel: true}},
    46. {type: 'category', gridIndex: 1, name: '日期', axisTick: {alignWithLabel: true}},
    47. {type: 'category', gridIndex: 2, name: '日期', axisTick: {alignWithLabel: true}},
    48. {type: 'category', gridIndex: 3, name: '日期', axisTick: {alignWithLabel: true}},
    49. ],
    50. yAxis: [
    51. {type: 'value',gridIndex: 0, name: '金额($)'},
    52. {type: 'value',gridIndex: 1, name: '数量'},
    53. {type: 'value',gridIndex: 2, name: '金额($)'},
    54. {type: 'value',gridIndex: 3, name: '%'},
    55. ],
    56. series: [
    57. // 配置数据关系
    58. // stack用来做分组标记,同标记的数据,会在同一个表格显示
    59. // seriesLayoutBy 设置如何从dateset里面获取数据,这里按照列获取
    60. {type: 'line', stack:'1', xAxisIndex: 0, yAxisIndex: 0, seriesLayoutBy: 'column'},
    61. {type: 'bar', stack:'2', xAxisIndex: 1, yAxisIndex: 1, seriesLayoutBy: 'column'},
    62. {type: 'bar', stack:'3', xAxisIndex: 2, yAxisIndex: 2, seriesLayoutBy: 'column'},
    63. {type: 'line', stack:'4', xAxisIndex: 3, yAxisIndex: 3, seriesLayoutBy: 'column',
    64. label: {
    65. show: true,
    66. position: 'top',
    67. formatter: function (params) {
    68. return params.value[4] + '%';
    69. },
    70. },},
    71. ]
    72. };
    73. // 使用刚指定的配置项和数据显示图表。
    74. myChart.setOption(option);
    75. script>
    76. body>
    77. html>

    4、效果

  • 相关阅读:
    23种设计模式 9组合模式
    如何与Excel聊天?
    Java 是什么?Java 的特性、编程环境
    零基础转行次世代3D建模,这3点看了再转
    指纹浏览器是什么?可以用来解决流量套利的什么问题?
    BigDecimal使用
    LeetCode_二分搜索_中等_2594.修车的最少时间
    调整参数提高mysql读写速度
    d用户反驳移植到jai的经验
    论文解读-DeepEdit:使用纳米孔直接RNA测序对A - to - I RNA编辑事件进行单分子检测和阶段划分
  • 原文地址:https://blog.csdn.net/qq_60735796/article/details/136140078