Echarts统计图使用记录

本文详细介绍了如何使用Echarts库创建柱状图,包括设置提示框、网格、坐标轴、系列等属性,以及如何自定义颜色、文字样式和网格线。示例代码展示了柱状图的完整配置,帮助读者理解Echarts图表的制作过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

官网地址:https://echarts.apache.org/examples/zh/index.html

1. 柱状图

            var option = {
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow'
                    },
                    // 修改鼠标移到柱子上时,显示的内容
                    formatter: function (params) {
                        console.log(params);//打印断点,会看到自己想要的后台数据
                        return '发电量:' + params[0].value+'MW';
                    }
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: [
                    {
                        type: 'category',
                        data: xAxis_data,
                        axisTick: {
                            alignWithLabel: true
                        },
                        axisLabel: {
                            textStyle: {
                                color: '#000000', //更改坐标轴文字颜色
                                fontSize: 15      //更改坐标轴文字大小
                            },
                            margin: 10			//X轴线与文字之间的距离
                        },
                        axisLine: {
                            lineStyle: {
                                color: '#000000' //更改坐标轴颜色
                            }
                        }
                    }
                ],
                yAxis: [
                    {
                        type: 'value',
                        axisLabel: {
                            textStyle: {
                                color: '#ADFF2F',  //更改坐标轴文字颜色
                                fontSize: 16,      //更改坐标轴文字大小
                                fontWeight: 300    //字体的粗细
                            }
                        },
                        axisLine: {
                            lineStyle: {
                                color: '#ADFF2F' //更改坐标轴颜色
                            }
                        },
                        //修改横向网格线的颜色、宽度、线的类型
                        splitLine: {
                            show: true,
                            lineStyle: {
                                color: ['#000000'],
                                width: 1,
                                type: 'solid'
                            }
                        }
                    }
                ],
                series: [
                    {
                        name: '发电量',
                        type: 'bar',
                        barWidth: '60%',
                        data: series_data,
                        //柱子的颜色
                        itemStyle: {
                            normal: {
                                color: '#ADFF2F'
                            }
                        },
                    }
                ]
            };

            // 基于准备好的dom,初始化echarts图表
            var myChartBar = echarts.init(document.getElementById("chart"));
            // 过渡---------------------
            myChartBar.showLoading({
                text: '读取数据中...'  //loading话术
            });

            myChartBar.setOption(option);
            myChartBar.dispatchAction({
                type: "highlight",
                seriesIndex: 0,
                dataIndex: 0
            }); //设置默认选中高亮部分
            myChartBar.hideLoading();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值