快速开发ECharts

2018-12-23  本文已影响0人  vailter

快速开发ECharts

1. 导入js

 <!-- 引入 ECharts 文件 -->
 <script src="echarts.min.js"></script>

2. 初始化一个EChart

var initECharts = function () {
    leheDebitProvinceTrendChart = echarts.init($('#lehe_debit_province_trend')[0], echart_theme);
    leheAlipayProvinceTrendChart = echarts.init($('#lehe_alipay_province_trend')[0], echart_theme);
    leheCreditProvinceTrendChart = echarts.init($('#lehe_credit_province_trend')[0], echart_theme);

    leheDebitProvinceTrendChart.setOption(buildBlankMultiLineOption());
    leheAlipayProvinceTrendChart.setOption(buildBlankMultiLineOption());
    leheCreditProvinceTrendChart.setOption(buildBlankMultiLineOption());
};

/**
 * 构建空的折线图
 * @returns
 */
function buildBlankMultiLineOption() {
    return {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'cross',
                label: {
                    backgroundColor: '#6a7985'
                }
            }
        },
        legend: {
            data: []
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        // toolbox: {
        //     feature: {
        //         saveAsImage: {}
        //     }
        // },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: []
        },
        yAxis: [
            {
                type: 'value'
            }
        ],
        series: []
    };
}

3.动态加载数据

var option = echart.getOption();
option.legend[0].data= legend_data;
option.xAxis[0].data = x_axis_month;
option.series = series;
echart.hideLoading();
echart.setOption(option, true);

这样就可以选择ECharts官网的图表快速开发

上一篇下一篇

猜你喜欢

热点阅读