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);
}
多折线图生成

效果如图
1

//绘制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

转载于:https://www.cnblogs.com/Lulus/p/10662093.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用Angular和TypeScript来实现ECharts的柱状图。以下是一个简单的示例: 首先,确保你的Angular项目已经安装了echarts依赖: ```bash npm install echarts --save ``` 然后,在需要使用柱状图的组件,你可以按照以下步骤进行操作: 1. 在组件的HTML模板添加一个div容器,用于渲染ECharts图表: ```html <div id="chartContainer" style="width: 600px; height: 400px;"></div> ``` 2. 在组件的TypeScript文件引入ECharts和相关的类型定义: ```typescript import * as echarts from 'echarts'; ``` 3. 在组件的生命周期钩子函数,初始化ECharts图表并配置数据: ```typescript export class YourComponent implements OnInit { ngOnInit() { this.initChart(); } initChart() { const chartContainer = document.getElementById('chartContainer'); const chart = echarts.init(chartContainer); const option = { xAxis: { type: 'category', data: ['A', 'B', 'C', 'D', 'E'] }, yAxis: { type: 'value' }, series: [{ type: 'bar', data: [10, 20, 30, 40, 50] }] }; chart.setOption(option); } } ``` 在上面的示例,我们使用了一个简单的数据集来创建柱状图,x轴表示类别,y轴表示值。 注意:你可以根据自己的需求修改配置和数据。 4. 最后,在组件的样式文件为图表容器设置宽度和高度: ```css #chartContainer { width: 600px; height: 400px; } ``` 这样,你就可以在你的Angular项目使用ECharts来实现柱状图了。记得根据你的实际需求进行配置和样式的调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值