唯品秀前端博客

第一种方法echarts-for-react

1.添加依赖

1
2
3
4
```
npm install echarts-for-react --save
npm install echarts --save
``

2.成功后显示

3.在react页面引入Echarts

1
2
3
import React, { Component } from 'react'
import ReactEcharts from 'echarts-for-react';
import echarts from 'echarts';

4.声明

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
`
//把你在echar中编辑好的文件放在这个声明的对象中;
let echartsOption = {
    tooltip: {
        trigger: 'item',
        formatter: "{a} {
            b
        }: {
            c
        }({
            d
        } % )
        "

    },
    legend: {
        orient: 'vertical',
        x: 'left',
        data: ['天海湾', '鼎龙湾', '珍珠湾', '翠逸家园', '紫林湾'] //需要对应 series 的 name值
    },
    series: [
xxxxxxxxxxxxxxxxxxxx
xxxxxxxxx
]
}

5.注入到render 中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
render() {
    return ( <
        div id = "kidAlert" > {
            this.echartsElement = e
        }
    }
    option = {
        echartsOption
    }
    notMerge = {
        true
    } // 重新渲染数据的 重绘的,老坑了
    theme = "clear"
    style = {
        kidAlert
    } //这个图表的大小
    /></div >
)
}

#第二种方法echarts

1.导入echars

1
import echarts from 'echarts';

2.声明一波

1
2
3
4
5
render() {
    return ( <
        div id = "kidGraph" > < /div>
    )
}

3.编写代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
let echartsOption = {
title: {
    text: 'ECharts 入门示例'
},
tooltip: {},
xAxis: {
    data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
},
yAxis: {},
series: [{
    name: '销量',
    type: 'bar',
    data: [5, 20, 36, 10, 10, 20]
}]
});
}
class KpiGraph extends Component {
    constructor(props, context) {
        super(props, context)
        this.state = {}
    }
    componentDidMount() {
        this.newGraph()
    }
    newGraph() {
        var myChart = echarts.init(document.getElementById('kidGraph'));
        myChart.setOption(echartsOption)
    }
}

##只是学习,有误地方还请多多指点

本站所有文章、图片、资源等如无特殊说明或标注,均为来自互联网或者站长原创,版权归原作者所有;仅作为个人学习、研究以及欣赏!如若本站内容侵犯了原著者的合法权益,可联系我们进行处理,邮箱:343049466@qq.com
赞(0) 打赏

上一篇:

下一篇:

相关推荐

0 条评论关于"React脚手架项目中如何快速引入并使用echarts.js"

表情

最新评论

    暂无留言哦~~
谢谢你请我吃鸡腿*^_^*

支付宝扫一扫打赏

微信扫一扫打赏