echarts数据过多,横坐标数据名称显示不全,echarts滚动条

该代码示例展示了如何在Vue.js组件中使用Echarts库来初始化一个柱状图,展示水位-流量数据。方法包括设置图表配置,如标题、坐标轴、数据区域缩放以及监听legendselectchanged事件来处理图例选中状态。同时,当传入的day和num属性变化时,会自动更新图表数据。
<template>
    <div>
        <div id="echart" ref="echart" style="width: 100%;height: 300px;"></div>
    </div>
</template>
<script>
export default {
    props: {
        day: {
            type: Array,
            default: function () {
                return []
            }
        },
        num: {
            type: Array,
            default: function () {
                return []
            }
        }
    },
    data() {
        return {
            myChart: null,
        }
    },
    methods: {
        initBar(day, num) {
            let dateline = this.$refs.echart
            this.myChart = this.$echarts.init(dateline);
            this.myChart.clear();
            var op = {
                title: {
                    text: "水位-流量曲线图",
                    left: "60",
                    show: false
                },
                xAxis: {
                    name: "时间",
                    type: "category",
                    data: day,
                    left: "60",
                    axisTick: {
                        alignWithLabel: true
                    }
                },
                yAxis: [
                    {
                        name: "m³",
                        alignTicks: true,
                        type: "value",
                        // splitLine: {
                        //     show: false
                        // }
                    },
                ],
                tooltip: {
                    trigger: "axis",
                },
                grid: {
                    left: "24",
                    right: "5%",
                    bottom: "50",
                    top: "20%",
                    containLabel: true,
                },
                legend: {
                    show: true,
                    right: "10px",
                    textStyle: {
                        color: "#000",
                        padding: [3, 0, 0, 0]
                    }
                },
                dataZoom: [
                    {
                        type: 'inside',
                        start: 0,
                        end: 100
                    },
                    {
                        start: 0,
                        end: 100
                    }
                ],
                color: ['#25A4FF', '#43A478'],
                series: [
                    {
                        name: "供水量",
                        data: num,
                        type: "bar",
                    },
                ],
            };
            this.myChart.setOption(op);
            this.echclick(this.myChart)
        },
        echclick(myChart) {
            myChart.on("legendselectchanged", function (params) {
                let option = this.getOption();
                let select_value = Object.values(params.selected);
                let n = 0;
                select_value.map((res) => {
                    if (!res) {
                        n++;
                    }
                });
                if (n == select_value.length) {
                    option.legend[0].selected[params.name] = true;
                }
                this.setOption(option);
            });
        },
    },
    watch:{
        day:{
            handler(){
                this.initBar(this.day, this.num)
            }
        }
    }
}
</script>

dataZoom 组件 用于区域缩放 具体见文档Documentation - Apache ECharts

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值