ECHARTS实际应用-一个接口,单一页面,多个表格

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

<!-- 编写HTML文件-->
<!-- 引入你下载的min.js文件-->
<script src="{$Think.const.PUBLIC_PATH}/js/echarts.min.js"></script>

<!-- 添加目标DIV -->
<div id="sales_total" style="width: 1600px;height:700px;display: inline-block;"></div>
// 基于准备好的dom,初始化echarts实例
// sales_total 为目标DIV的idvar myChart = echarts.init(document.getElementById('sales_total'));

// 指定图表的配置项和数据
var option = {
    title: [  // 指定各个表格的标题
        {text: '销售额', top: '5%', left: '30%'},
        {text: '订单量', top: '5%', left: '75%'},
        {text: '客单价', left: '30%', top: '50%'},
        {text: '动销率', left: '75%', top: '50%',},
    ],
    dataset: { // 指定数据源
        source:
            [
                ['type','销售额', '订单量', '客单价', '动销率'],
            ].concat(
                [
                    ['2019-01-01',100.0,20,4,'30%'],
                    ['2019-01-02',110.0,21,5,'30%'],
                    ['2019-01-03',120.0,22,6,'30%'],
                    ['2019-01-04',140.0,23,7,'30%'],
                    ['2019-01-05',150.0,24,8,'30%'],
                    ['2019-01-06',160.0,25,9,'30%'],
                ]
            )
    },
    grid: [ // 用来调整,各个表格的位置
        {top: '10%', bottom: '55%', width: '40%'},
        {top: '10%', bottom: '55%',left: '55%', width: '40%'},
        {top: '55%', width: '40%'},
        {top: '55%', left: '55%', width: '40%'},
    ],
    tooltip: {},
    legend: {},
    xAxis: [ // 用来配置横坐标的信息,gridIndex是标识针对的那个表格
        {type: 'category', gridIndex: 0, name: '日期', axisTick: {alignWithLabel: true}},
        {type: 'category', gridIndex: 1, name: '日期', axisTick: {alignWithLabel: true}},
        {type: 'category', gridIndex: 2, name: '日期', axisTick: {alignWithLabel: true}},
        {type: 'category', gridIndex: 3, name: '日期', axisTick: {alignWithLabel: true}},
    ],
    yAxis: [
        {type: 'value',gridIndex: 0, name: '金额($)'},
        {type: 'value',gridIndex: 1, name: '数量'},
        {type: 'value',gridIndex: 2, name: '金额($)'},
        {type: 'value',gridIndex: 3, name: '%'},
    ],
    series: [

        // 配置数据关系
        // stack用来做分组标记,同标记的数据,会在同一个表格显示
        // seriesLayoutBy 设置如何从dateset里面获取数据,这里按照列获取
        {type: 'line', stack:'1', xAxisIndex: 0, yAxisIndex: 0, seriesLayoutBy: 'column'},
        {type: 'bar', stack:'2', xAxisIndex: 1, yAxisIndex: 1, seriesLayoutBy: 'column'},
        {type: 'bar', stack:'3', xAxisIndex: 2, yAxisIndex: 2, seriesLayoutBy: 'column'},
        {type: 'line', stack:'4', xAxisIndex: 3, yAxisIndex: 3, seriesLayoutBy: 'column'},
    ]
};

// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);

效果如下图:
在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

落笔成名

客官,辛苦则个

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值