一个html引入多个柱状图,在react项目中使用ECharts在页面显示多个柱状图

最近项目比较赶,又跑来做前端了,简单写一下逻辑吧。

import React, { Component } from 'react';

//引入需要的标签

import { Table,Input,Row,Col } from 'apollo-react';

// 引入 ECharts 主模块

import echarts from 'echarts/lib/echarts';

// 引入柱状图

import 'echarts/lib/chart/bar';

// 引入提示框和标题组件

import 'echarts/lib/component/tooltip';

import 'echarts/lib/component/title';

class Catrogrom extends Component {

constructor(){

super();

//写入用到的变量

this.state={

loading:true,

numdata:[],

typedata:[],

ipad_num:[],

ipad_version:[],

}

}

fetchData=()=>{

this.state.loading({loading:true});

//请求后台数据如果有请求参数要写:let data = this.proms.from.getFieldsValue();

$.post('/system/getdata.json',{

//输入请求后台的请求参数,没写这里是无参,例:userName:data.userName

},(res)=>{

//要请求后台数据的参数,用于后面调用参数

numdata:res.deviceNum.num ,

typedata:res.deviceNum.type ,

ipad_num:res.versionNum.IPAD.num,

ipad_version:res.versionNum.IPAD.version;

}

);

this.zhuzhuangtu(this.state.numdata,this.state.numdata);

this.zhuzhuangtuipad(this.state. ipad_num,this.state.ipad_version);

}

zhuzhuangtu(countNum,countType) {

// 基于准备好的dom,初始化echarts实例

var myChart = echarts.init(document.getElementById('main'));

// 绘制图表

myChart.setOption({

title: { text: 'ECharts 入门示例' },

tooltip: {},

xAxis: {

data: countNum

},

yAxis: {},

series: [{

name: '销量',

type: 'bar',

data: countType

}]

});

}

zhuzhuangtuipad(countNum,countType) {

// 基于准备好的dom,初始化echarts实例

var myChart = echarts.init(document.getElementById('ipad'));

// 绘制图表

myChart.setOption({

title: { text: 'ECharts 入门示例' },

tooltip: {},

xAxis: {

data: countNum

},

yAxis: {},

series: [{

name: '销量',

type: 'bar',

data: countType

}]

});

}

//加载数据

componentDidMount=()=>{

this.fetchData();

}

render() {

return (

);

}

}

export default Catrogrom;

效果图:

81adf6f17180?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值