微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Angular使用echarts

安装

npm install echarts --save
npm install @types/echarts --save

基本使用

定义一个dom

<div id="chart" style="min-width: 1500px;min-height:800px;"></div>

定义对象

//数据
eChartDatas: any;
//图例
legends:any;

//echart
echarts: any;
myChart: any;

获得echarts对象

// 基于准备好的dom,初始化echarts实例
this.echarts = require('echarts');
//只能初始化一次:https://www.echartsjs.com/api.html#echarts.init
if (this.myChart == null || this.myChart == undefined) {
  this.myChart = this.echarts.init(document.getElementById('chart') as HTMLdivelement);
}

多折线图生成

//绘制chart
// 指定图表的配置项和数据
var option = {
    //标题
    title: {
    text: '监测数据统计图',
    // left: 'center'
    },
    //图例
    legend: {
        data: this.legends
    },
    tooltip: {
    trigger: 'axis',
    grid: {
    left: '3%',
    right: '4%',
    bottom: '3%',
    containLabel: true
    },
    toolBox: {
    feature: {
        saveAsImage: {}
    }
    },
    xAxis: {
    type: 'time',
    splitLine: {
        show: false
    }
    },
    yAxis: {
    type: 'value',
    splitLine: {
        show: false
    }
    },
    series: []
};
//循环录入数据
this.eChartDatas.forEach(dataList => {
    option.series.push({
    name: dataList[0].tip,
    type: 'line',
    showSymbol: false,
    hoverAnimation: false,
    data: dataList
    });
});

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

示例代码

示例代码

参考资料

Is it possible to use ECharts Baidu with Angular 2 and TypeScript
Ionic2系列——在Ionic2中使用ECharts
echarts demo
echarts 多折线demo

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐