首页 前端知识 vue echarts 多个折线图

vue echarts 多个折线图

2024-04-16 17:04:54 前端知识 前端哥 858 786 我要收藏

在这里插入图片描述

<div id="echartsSigns" style="height: 700px;width:900px;margin: auto;"></div>
复制
// 时间线
this.overviewDate = [
"16:32",
"16:32",
"16:55"
]
this.bodyTemperatureList =[ 36, 39, 38]
// 心率
this.heartRateList = [ 85, 69, 99]
// 呼吸
this.breatheList =[ 74, 88, 65]
this.bloodPressureMaxList =[77, 88, 65 ]
this.bloodPressureMinList = [88, 88,65 ]
this.oxygenSaturationList =[74, 88, 56]
//图表代码
// 图表
chartFn() {
// 基于准备好的dom,初始化echarts实例
const myChart = echarts.init(document.getElementById('echartsSigns'));
//图表定位
const chartGridTop = 30;
const chartGridHeight = 100;
// 绘制图表
const option = {
animation: false,
legend: {
data: ['体温', '心率', '呼吸', '舒张压', '收缩压', '血氧'],
top: "0%",
// right: "15%",
bottom: "50%",
icon: 'roundRect',
},
tooltip: {
//移动端展示方式
trigger: 'axis',
transitionDuration: 0,
confine: true,
borderRadius: 4,
padding: 5,
borderWidth: 0,
backgroundColor: 'rgba(0, 0, 0,0.5)',
textStyle: {
fontSize: 14,
color: '#fff'
},
formatter: function (params) { //数据单位格式化
var relVal = params[0].name; //x轴名称
relVal += "<div style='width:150px;'>"
for (var i = 0, l = params.length; i < l; i++) {
if (params[i].seriesName === "体温") {
if (params[i].value) {
relVal += "<span style='display:inline-block;margin-right:5px;width:10px;height:10px;background-color:" + params[i].color + ";'>" + '<span style="display:block;padding-left:15px;margin-top:-4px">' + params[i].seriesName + ' : ' + params[i].value + '℃' + '</span>' + "</span>" + '<br>';
}
}
if (params[i].seriesName === "心率") {
if (params[i].value) {
relVal += "<span style='display:inline-block;margin-right:5px;width:10px;height:10px;background-color:" + params[i].color + ";'>" + '<span style="display:block;padding-left:15px;margin-top:-4px">' + params[i].seriesName + ' : ' + params[i].value + 'bmp' + '</span>' + "</span>" + '<br>';
}
}
if (params[i].seriesName === "呼吸") {
if (params[i].value) {
relVal += "<span style='display:inline-block;margin-right:5px;width:10px;height:10px;background-color:" + params[i].color + ";'>" + '<span style="display:block;padding-left:15px;margin-top:-4px">' + params[i].seriesName + ' : ' + params[i].value + '次' + '</span>' + "</span>" + '<br>';
}
}
if (params[i].seriesName === "收缩压") {
if (params[i].value) {
relVal += "<span style='display:inline-block;margin-right:5px;width:10px;height:10px;background-color:" + params[i].color + ";'>" + '<span style="display:block;padding-left:15px;margin-top:-4px">' + params[i].seriesName + ' : ' + params[i].value + 'mmHg' + '</span>' + "</span>" + '<br>';
}
}
if (params[i].seriesName === "舒张压") {
if (params[i].value) {
relVal += "<span style='display:inline-block;margin-right:5px;width:10px;height:10px;background-color:" + params[i].color + ";'>" + '<span style="display:block;padding-left:15px;margin-top:-4px">' + params[i].seriesName + ' : ' + params[i].value + 'mmHg' + '</span>' + "</span>" + '<br>';
}
}
if (params[i].seriesName === "血氧") {
if (params[i].value) {
relVal += "<span style='display:inline-block;margin-right:5px;width:10px;height:10px;background-color:" + params[i].color + ";'>" + '<span style="display:block;padding-left:15px;margin-top:-4px">' + params[i].seriesName + ' : ' + params[i].value + '%' + '</span>' + "</span>" + '<br>';
}
}
}
relVal += "</div>"
return relVal;
}
},
//坐标轴指示器(axisPointer)的全局公用设置
axisPointer: {
// type: 'shadow',
link: {
xAxisIndex: 'all'
}
},
//直角坐标系内绘图网格
grid: [
this.makeGrid(chartGridTop, chartGridHeight),
this.makeGrid(chartGridTop + (chartGridHeight + 20), chartGridHeight),
this.makeGrid(chartGridTop + (chartGridHeight + 20) * 2, chartGridHeight),
this.makeGrid(chartGridTop + (chartGridHeight + 20) * 3, chartGridHeight),
this.makeGrid(chartGridTop + (chartGridHeight + 20) * 4, chartGridHeight),
],
xAxis: [
this.makeXAxis(0),
this.makeXAxis(1),
this.makeXAxis(2),
this.makeXAxis(3),
this.makeXAxis(4),
],
yAxis: [
this.makeYAxis(0, {
name: '体温',
// splitLine: false,//去除网格线
}),
this.makeYAxis(1, {
name: '心率',
// splitNumber: 2,
}),
this.makeYAxis(2, {
name: '呼吸',
// splitNumber: 3,
}),
this.makeYAxis(3, {
name: '血压',
// splitNumber: 3,
}),
this.makeYAxis(4, {
name: '血氧',
}),
],
//dataZoom 组件 用于区域缩放
dataZoom: [{
type: 'slider',
xAxisIndex: [0, 1, 2, 3],
realtime: true,
//移动端展示方式
handleSize: '140%',
}],
//每个系列通过 type 决定自己的图表类型
series: [
this.makeGridData(0, 0, 'line', '体温', this.bodyTemperatureList, {
stack: 'DBTIME', smooth: false, color: '#6DD400',
// 设置拐点
// symbol: "circle",
// 拐点大小
symbolSize: 8,
// 开始不显示拐点, 鼠标经过显示
showSymbol: false,
// 设置拐点颜色以及边框
// itemStyle: {
// color: "#0184d5",
// borderColor: "rgba(221, 220, 107, .1)",
// borderWidth: 12
// },
// 填充颜色设置
areaStyle: {
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(109, 212, 0, 0.4)" // 渐变色的起始颜色
},
{
offset: 0.8,
color: "rgba(109, 212, 0, 0.1)" // 渐变线的结束颜色
}
],
false
),
shadowColor: "rgba(0, 0, 0, 0.1)"
},
}),
this.makeGridData(1, 1, 'line', '心率', this.heartRateList, {
smooth: false, color: '#35BAE9',
// 设置拐点
// symbol: "circle",
// 拐点大小
symbolSize: 8,
// 开始不显示拐点, 鼠标经过显示
showSymbol: false,
// 设置拐点颜色以及边框
// itemStyle: {
// color: "#0184d5",
// borderColor: "rgba(221, 220, 107, .1)",
// borderWidth: 12
// },
areaStyle: {
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(53, 186, 233, 0.4)" // 渐变色的起始颜色
},
{
offset: 0.8,
color: "rgba(53, 186, 233, 0.1)" // 渐变线的结束颜色
}
],
false
),
shadowColor: "rgba(0, 0, 0, 0.1)"
},
}),
this.makeGridData(2, 2, 'line', '呼吸', this.breatheList, {
smooth: false, color: '#4A45CF',
// 设置拐点
// symbol: "circle",
// 拐点大小
symbolSize: 8,
// 开始不显示拐点, 鼠标经过显示
showSymbol: false,
// 设置拐点颜色以及边框
// itemStyle: {
// color: "#0184d5",
// borderColor: "rgba(221, 220, 107, .1)",
// borderWidth: 12
// },
areaStyle: {
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(74, 69, 207, 0.4)" // 渐变色的起始颜色
},
{
offset: 0.8,
color: "rgba(74, 69, 207, 0.1)" // 渐变线的结束颜色
}
],
false
),
shadowColor: "rgba(0, 0, 0, 0.1)"
},
}),
this.makeGridData(3, 3, 'line', '收缩压', this.bloodPressureMaxList, {
smooth: false, color: '#F38A27',
// 设置拐点
// symbol: "circle",
// 拐点大小
symbolSize: 8,
// 开始不显示拐点, 鼠标经过显示
showSymbol: false,
// 设置拐点颜色以及边框
// itemStyle: {
// color: "#0184d5",
// borderColor: "rgba(221, 220, 107, .1)",
// borderWidth: 12
// },
areaStyle: {
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(243, 138, 39, 0.4)" // 渐变色的起始颜色
},
{
offset: 0.8,
color: "rgba(243, 138, 39, 0.1)" // 渐变线的结束颜色
}
],
false
),
shadowColor: "rgba(0, 0, 0, 0.1)"
},
}),
this.makeGridData(3, 3, 'line', '舒张压', this.bloodPressureMinList, {
smooth: false, color: '#F7C92F',
// 设置拐点
// symbol: "circle",
// 拐点大小
symbolSize: 8,
// 开始不显示拐点, 鼠标经过显示
showSymbol: false,
// 设置拐点颜色以及边框
// itemStyle: {
// color: "#0184d5",
// borderColor: "rgba(221, 220, 107, .1)",
// borderWidth: 12
// },
areaStyle: {
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(247, 201, 47, 0.4)" // 渐变色的起始颜色
},
{
offset: 0.8,
color: "rgba(247, 201, 47, 0.1)" // 渐变线的结束颜色
}
],
false
),
shadowColor: "rgba(0, 0, 0, 0.1)"
},
}),
this.makeGridData(4, 4, 'line', '血氧', this.oxygenSaturationList, {smooth: false, color: '#FF5050',
// 设置拐
// symbol: "circle",
// 拐点大小
symbolSize: 8,
// 开始不显示拐点, 鼠标经过显示
showSymbol: false,
// 设置拐点颜色以及边框
// itemStyle: {
// color: "#0184d5",
// borderColor: "rgba(221, 220, 107, .1)",
// borderWidth: 12
// },
areaStyle: {
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(255, 80, 80, 0.4)" // 渐变色的起始颜色
},
{
offset: 0.8,
color: "rgba(255, 80, 80, 0.1)" // 渐变线的结束颜色
}
],
false
),
shadowColor: "rgba(0, 0, 0, 0.1)"
},
}),
]
}
myChart.setOption(option);
window.onresize = function () {
myChart.resize()
}
},
//直角坐标系内绘图网格
makeGrid(top, height, opt) {
return echarts.util.merge({
left: 70,
right: 60,
top: top,
height: height
}, opt || {}, true);
},
//X轴生成器
makeXAxis(gridIndex, opt) {
//避免X轴数据显示过于频繁
this.axisLabelFlag = false;
// if (gridIndex % 2 == 0) {
// axisLabelFlag = true;
// }
if (gridIndex == 4) {
this.axisLabelFlag = true;
}
return echarts.util.merge({
type: 'category',
gridIndex: gridIndex,
//统一时间轴数据
data: this.overviewDate,
// axisTick: {
// show: false // 去除刻度线
// },
axisLabel: {
show: this.axisLabelFlag,
color: '#333333',
fontSize: '12',
fontWeight: 500
},
}, opt || {}, true);
},
//Y轴生成器
makeYAxis(gridIndex, opt) {
return echarts.util.merge({
type: 'value',
nameLocation: 'center',
nameGap: '40',
nameRotate: 0,
gridIndex: gridIndex,
nameTextStyle: {
color: '#333333',
fontSize: '14',
// fontWeight:600
},
axisTick: {
show: false
},
axisLabel: {
show: true,
textStyle: {
// align: 'left',
baseline: 'middle',
color: '#333333',
fontSize: '12',
fontWeight: 500,
},
},
axisLine: {
show: true
}
}, opt || {}, true);
},
//数据生成器
makeGridData(xAxisIndex, yAxisIndex, chartType, chartName, chartData, opt) {
return echarts.util.merge({
type: chartType,
name: chartName,
xAxisIndex: xAxisIndex,
yAxisIndex: yAxisIndex,
data: chartData,
}, opt || {}, true);
}
复制
转载请注明出处或者链接地址:https://www.qianduange.cn//article/5063.html
标签
评论
发布的文章

JQuery中的load()、$

2024-05-10 08:05:15

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!