当前位置: 首页 > wzjs >正文

如何自己免费建网站友情链接qq群

如何自己免费建网站,友情链接qq群,冰雪蜜城店加盟费多少,php做网站基本流程文章目录一、引言二、项目背景三、实现多系列柱状图1) 场景描述2) 数据准备3) 图表配置与初始化4) 效果说明四、实现堆叠曲线图1) 场景描述2) 数据准备3) 图表配置与初始化4) 效果说明五、完整代码总结一、引言 在数据可视化领域,图表是展示复杂数据的重要工具。在…

文章目录

    • 一、引言
    • 二、项目背景
    • 三、实现多系列柱状图
      • 1) 场景描述
      • 2) 数据准备
      • 3) 图表配置与初始化
      • 4) 效果说明
    • 四、实现堆叠曲线图
      • 1) 场景描述
      • 2) 数据准备
      • 3) 图表配置与初始化
      • 4) 效果说明
    • 五、完整代码
    • 总结


一、引言

在数据可视化领域,图表是展示复杂数据的重要工具。在Vue3项目中,结合ECharts库,我们可以轻松实现各种类型的图表展示,帮助用户更直观地理解数据背后的规律。本文将详细介绍如何在Vue3中实现两种常见的图表类型:多系列柱状图堆叠曲线图,并结合实际场景进行数据展示。

二、项目背景

假设我们正在开发一个智能农业监控系统,需要展示不同农业设备的能耗数据以及不同大棚的温度变化数据。系统需要展示两种类型的图表:

  • 多系列柱状图:展示不同月份下,两个不同年份的灌溉系统能耗对比。
  • 堆叠曲线图:展示不同农业设备在一天中的能耗变化趋势。

三、实现多系列柱状图

1) 场景描述

我们监控某农业基地的月度灌溉系统能耗数据,对比2023年和2024年各月份的能耗情况。通过柱状图,可以直观地看到不同年份同一月份的能耗差异,帮助分析能耗变化趋势。

2) 数据准备

const barChartData = {categories: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],values1: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120], // 2023年数据values2: [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115]    // 2024年数据
}

3) 图表配置与初始化

let barChartInstance = null;const initBarChart = () => {const chartDom = document.getElementById('barChart');if (!chartDom) return;barChartInstance = echarts.init(chartDom);const option = {tooltip: {trigger: 'axis',axisPointer: {type: 'shadow'}},legend: {data: ['2023年灌溉能耗', '2024年灌溉能耗'],top: 10,textStyle: {color: '#333'}},grid: {left: '3%',right: '4%',bottom: '3%',containLabel: true},xAxis: {type: 'category',data: barChartData.categories,axisLine: {lineStyle: {color: '#d1d8e0'}}},yAxis: {type: 'value',splitLine: {lineStyle: {color: '#eee'}},axisLine: {lineStyle: {color: '#d1d8e0'}},name: '能耗(kWh)'},series: [{name: '2023年灌溉能耗',type: 'bar',data: barChartData.values1,itemStyle: {color: '#5470C6'},barWidth: '40%'},{name: '2024年灌溉能耗',type: 'bar',data: barChartData.values2,itemStyle: {color: '#91CC75'},barWidth: '40%'}]};barChartInstance.setOption(option);
};

4) 效果说明

  • 图表展示了2023年和2024年各月份的灌溉系统能耗对比。
  • 蓝色柱子代表2023年数据,绿色柱子代表2024年数据。
  • 鼠标悬停在柱子上时,会显示具体数值,方便对比分析。

四、实现堆叠曲线图

1) 场景描述

我们监控农业基地内不同设备(如灌溉泵、温室通风机、补光灯等)在一天中的能耗变化。通过堆叠曲线图,可以清晰地看到各设备在不同时间段的能耗占比,以及整体能耗的变化趋势。

2) 数据准备

const chartDataStacked = {categories: ['00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00'],series: [{ name: '灌溉泵', data: [10, 20, 15, 25, 30, 22, 10, 20, 15, 25, 30, 22, 10, 20, 15, 25, 30, 22, 10, 20, 15, 25, 30, 22] },{ name: '温室通风机', data: [5, 15, 10, 20, 25, 17, 5, 15, 10, 20, 25, 17, 5, 15, 10, 20, 25, 17, 5, 15, 10, 20, 25, 17] },{ name: '补光灯', data: [8, 18, 13, 23, 28, 20, 8, 18, 13, 23, 28, 20, 8, 18, 13, 23, 28, 20, 8, 18, 13, 23, 28, 20] },{ name: '温控系统', data: [12, 22, 17, 27, 32, 24, 12, 22, 17, 27, 32, 24, 12, 22, 17, 27, 32, 24, 12, 22, 17, 27, 32, 24] }]
};

3) 图表配置与初始化

let stackedChartInstance = null;const initStackedChart = () => {const chartDom = document.getElementById('stackedLineChart');if (!chartDom) return;stackedChartInstance = echarts.init(chartDom);const option = {tooltip: {trigger: 'axis',backgroundColor: 'rgba(0, 0, 0, 0.7)',borderColor: '#333',textStyle: { color: '#fff' }},legend: {data: chartDataStacked.series.map(item => item.name),top: 30,textStyle: { color: '#333' }},grid: {left: '3%',right: '4%',bottom: '3%',containLabel: true},xAxis: {type: 'category',boundaryGap: false,data: chartDataStacked.categories,axisLine: {lineStyle: {color: '#d1d8e0'}}},yAxis: {type: 'value',name: '能耗(kWh)',axisLine: {lineStyle: {color: '#d1d8e0'}}},series: chartDataStacked.series.map(item => ({name: item.name,type: 'line',stack: '总量',smooth: true,lineStyle: {width: 2},data: item.data}))};stackedChartInstance.setOption(option);
};

4) 效果说明

  • 图表展示了灌溉泵、温室通风机、补光灯和温控系统在一天中的能耗变化。
  • 曲线采用堆叠方式,可以清晰地看到各设备在不同时间段的能耗占比。
  • 鼠标悬停在曲线上时,会显示具体数值和设备名称,方便分析。

五、完整代码

<template><div class="chart-container"><div id="barChart" class="chart"></div><div id="stackedLineChart" class="chart"></div></div>
</template><script setup>
import { onMounted, onBeforeUnmount } from 'vue';
import * as echarts from 'echarts';// 柱状图数据 - 灌溉系统月度能耗对比
const barChartData = {categories: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],values1: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120], // 2023年数据values2: [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115]    // 2024年数据
};// 堆叠曲线图数据 - 农业设备24小时能耗变化
const chartDataStacked = {categories: ['00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00','12:00', '13:00', '14:00', '15:00', '16:00', '17:00','18:00', '19:00', '20:00', '21:00', '22:00', '23:00'],series: [{ name: '灌溉泵', data: [10, 20, 15, 25, 30, 22, 10, 20, 15, 25, 30, 22, 10, 20, 15, 25, 30, 22, 10, 20, 15, 25, 30, 22] },{ name: '温室通风机', data: [5, 15, 10, 20, 25, 17, 5, 15, 10, 20, 25, 17, 5, 15, 10, 20, 25, 17, 5, 15, 10, 20, 25, 17] },{ name: '补光灯', data: [8, 18, 13, 23, 28, 20, 8, 18, 13, 23, 28, 20, 8, 18, 13, 23, 28, 20, 8, 18, 13, 23, 28, 20] },{ name: '温控系统', data: [12, 22, 17, 27, 32, 24, 12, 22, 17, 27, 32, 24, 12, 22, 17, 27, 32, 24, 12, 22, 17, 27, 32, 24] }]
};let barChartInstance = null;
let stackedChartInstance = null;// 初始化柱状图
const initBarChart = () => {const chartDom = document.getElementById('barChart');if (!chartDom) return;barChartInstance = echarts.init(chartDom);const option = {title: {text: '灌溉系统月度能耗对比',left: 'center',textStyle: {color: '#333'}},tooltip: {trigger: 'axis',axisPointer: {type: 'shadow'},formatter: params => {const data = params[0];return `${data.axisValue}<br/>${data.seriesName}: ${data.value}kWh`;}},legend: {data: ['2023年灌溉能耗', '2024年灌溉能耗'],top: 30,textStyle: {color: '#333'}},grid: {left: '3%',right: '4%',bottom: '3%',containLabel: true},xAxis: {type: 'category',data: barChartData.categories,axisLine: {lineStyle: {color: '#d1d8e0'}},axisLabel: {color: '#666'}},yAxis: {type: 'value',name: '能耗(kWh)',nameTextStyle: {color: '#333'},splitLine: {lineStyle: {color: '#eee'}},axisLine: {lineStyle: {color: '#d1d8e0'}},axisLabel: {color: '#666'}},series: [{name: '2023年灌溉能耗',type: 'bar',data: barChartData.values1,itemStyle: {color: '#5470C6'},barWidth: '40%',label: {show: true,position: 'top',color: '#333'}},{name: '2024年灌溉能耗',type: 'bar',data: barChartData.values2,itemStyle: {color: '#91CC75'},barWidth: '40%',label: {show: true,position: 'top',color: '#333'}}]};barChartInstance.setOption(option);
};// 初始化堆叠曲线图
const initStackedChart = () => {const chartDom = document.getElementById('stackedLineChart');if (!chartDom) return;stackedChartInstance = echarts.init(chartDom);const option = {title: {text: '农业设备24小时能耗变化',left: 'center',textStyle: {color: '#333'}},tooltip: {trigger: 'axis',backgroundColor: 'rgba(0, 0, 0, 0.7)',borderColor: '#333',textStyle: { color: '#fff' },formatter: params => {let result = `${params[0].axisValue}<br/>`;params.forEach(item => {result += `${item.marker} ${item.seriesName}: ${item.value}kWh<br/>`;});return result;}},legend: {data: chartDataStacked.series.map(item => item.name),top: 30,textStyle: { color: '#333' }},grid: {left: '3%',right: '4%',bottom: '3%',containLabel: true},xAxis: {type: 'category',boundaryGap: false,data: chartDataStacked.categories,axis

总结

通过本文的介绍,我们学习了如何在Vue3中结合ECharts实现多系列柱状图和堆叠曲线图。柱状图适用于对比不同类别的数据,而堆叠曲线图则适合展示时间序列数据的变化趋势和占比。在实际项目中,可以根据具体需求调整图表配置,如颜色、标签、提示框等,以达到最佳的展示效果。

http://www.dtcms.com/wzjs/396369.html

相关文章:

  • 网站建设常态化工作机制搜索自媒体平台
  • 定制网站建设流程整站优化推广
  • 聊城做网站建设的公司顾问
  • 城口网站建设企业网站营销实现方式解读
  • 西城做网站公司营销推广有哪些公司
  • 宁德市蕉城区建设局网站爱站网能不能挖掘关键词
  • 徐州手机网站开发公司郑州seo优化哪家好
  • 南宁市保障住房建设管理服务中心网站企业微信会话内容存档
  • 中国建设部官方网站监理转注册电商推广
  • 软件定制需要多少钱某网站seo诊断分析
  • 品牌网站建设专业定制seo长尾关键词优化
  • wordpress+用户前台抖音关键词优化排名
  • 做网站多少钱西宁君博示范福州seo网站管理
  • 网站什么引导页网店培训机构
  • 网站建设热门吗东莞百度seo关键词优化
  • 大连网站建设优化常州seo建站
  • 网站怎么做实名认证网站开发
  • 西安代做毕业设计网站百度竞价是什么意思
  • 我要自学网网站开发seo百度排名优化
  • 动态网站成品网络营销的核心是什么
  • 行业网站推广方案企业推广公司
  • 全运会网站的建设北京外包seo公司
  • 淘客网站推广免备案网络推广合作协议范本
  • 有什么网站是可以做日语题自己有域名怎么建网站
  • axure做网站下拉菜单免费十大软件大全下载安装
  • 中国采购网关键词优化排名查询
  • 网站建设合同 附件seo代码优化包括哪些
  • 免费建设外贸网站怎样在百度上发帖子
  • 哪个网站能学做微商目前搜索引擎排名
  • 国外网站代理请输入搜索关键词