uniapp中echarts的简单使用

14 篇文章 0 订阅
3 篇文章 0 订阅
1.在DCLOUD插件市场导入echarts

基础用法

<view style="width: 100%; height:500rpx"><l-echart ref="chart"></l-echart></view>
import * as echarts from '@/uni_modules/lime-echart/components/l-echart/echarts';
export default {
    data() {
        return {
            option: {
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            // 坐标轴指示器,坐标轴触发有效
                            type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
                        },
                        confine: true
                    },
                    grid: {
                        left: 20,
                        right: 20,
                        bottom: 15,
                        top: 40,
                        containLabel: true
                    },
                    xAxis: [
                        {
                            type: 'value',
                            axisLine: {
                                lineStyle: {
                                    color: '#999999'
                                }
                            },
                            axisLabel: {
                                color: '#666666'
                            }
                        }
                    ],
                    yAxis: [
                        {
                            type: 'category',
                            axisTick: { show: false },
                            axisLine: {
                                lineStyle: {
                                    color: '#999999'
                                }
                            },
                            axisLabel: {
                                color: '#666666'
                            }
                        }
                    ],
                    dataset: {
			dimensions:['product', '收缩压', '舒张压'],
			source: [
							//存放数据
			]
		    },
                    series: [
                        {
                            name: '热度',
                            type: 'bar',
                            label: {
                                normal: {
                                    show: true,
                                    position: 'inside'
                                }
                            },
                            itemStyle: {
                                // emphasis: {
                                //   color: '#37a2da'
                                // }
                            }
                        },
                        {
                            name: '正面',
                            type: 'bar',
                            stack: '总量',
                            label: {
                                normal: {
                                    show: true
                                }
                            },
                            itemStyle: {
                                // emphasis: {
                                //   color: '#32c5e9'
                                // }
                            }
                        },
                        {
                            name: '负面',
                            type: 'bar',
                            stack: '总量',
                            label: {
                                normal: {
                                    show: true,
                                    position: 'left'
                                }
                            },
                            itemStyle: {
                                // emphasis: {
                                //   color: '#67e0e3'
                                // }
                            }
                        }
                    ]
                },
        };
    },
    mounted() {
        this.$refs.chart.init(config => {
            const { canvas } = config;
            const chart = echarts.init(canvas, null, config);
            canvas.setChart(chart);
            chart.setOption(this.option);
            // 需要把 chart 返回
            return chart;
        });
    }
}    

  要注意通过接口获取数据然后直接改变option配置项中的数据时,图表是不会更新的

所以需要调用这个this.$refs.chart.setOption(this.option,true),表示数据不默认合并。之后图标就会更新了

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值