关注女性健康,分享 echarts 绘制女性体温表源码

前言

关注女性健康,分享 echarts 绘制女性体温表源码。

最近每天早起睁眼的第一件事就是测舌下体温(水银体温计),要想测得准,测温时间要固定,作息也要规律。

静息体温的动态变化一定程度上可以反映女性黄体功能是否正常。

医生给的纸质体温表被我画错了一格,强迫症的我就想重画,可惜没有第二张。作为现在还是程序媛的我,突然就来了灵感,那就用 echarts 画一张电子版的吧。

哈哈,如果我是男生,画给女朋友,那就是另一个版本的浪漫故事了,可惜我老公是后端开发,不会前端。

 

正文来了

先看效果

从程序员的角度看,下面这种形式的呈现是比较完美的。

但是,医生一看就说不行。

于是,有了第二版本。

这个版本就很接近医生提供的那个纸质表格了。对,重点就是表格。

横纵最好是方格或接近方格。

x轴几经测试,发现放自然数最合适,表示是第几天。

要表示一个完整的月经周期,所以是30天左右。当然,如果能保证方格,可以连续绘制更好。

  

源码 

<!DOCTYPE html>

<html lang="en">

 

<head>

<meta charset="UTF-8">

<title>体温记录</title>

<script src="jquery-3.1.1.min.js"></script>

<script src="vue.js"></script>

<script src="echarts.min.js"></script>

 

<style>

#chartBarLine{

width: 100%;

height: 800px;

}

#chartLine{

width: 100%;

height: 800px;

}

</style>

</head>

 

<body>

<div id="root">

<div class="container">

<div class="echarts">

<!-- 方格折线图 -->

<div id="chartLine"></div>

<!-- 折现柱状图 -->

<div id="chartBarLine"></div>

</div>

</div>

</div>

 

<script>

new Vue({

el: "#root",

data() {

return {

}

},

methods: {

chartBarLine() {

// 基于准备好的dom,初始化echarts实例

var chartBarLine = echarts.init(document.getElementById('chartBarLine'));

 

// 指定图表的配置项和数据

var option = {

tooltip: {

trigger: 'axis',

axisPointer: {

label: {

backgroundColor: '#283b56'

}

}

},

toolbox: {

show: true,

feature: {

dataView: {

readOnly: false

},

restore: {},

saveAsImage: {}

}

},

dataZoom: {

show: false,

start: 0,

end: 100

},

grid: {

left: '10%',

bottom: '26%',

top: '30%'

},

xAxis: [{

type: 'category',

boundaryGap: true,

axisLabel: {

interval: 0,

rotate: 40

},

data: ["2020-12-28", "2020-12-29", "2020-12-30", "2020-12-31", "2021-01-01", "2021-01-02", "2021-01-03", "2021-01-04", "2021-01-05","2021-01-06" ,"2021-01-07","2021-01-08","2021-01-09","2021-01-10","2021-01-11","2021-01-12","2021-01-13","2021-01-14","2021-01-15","2021-01-16","2021-01-17","2021-01-18","2021-01-19","2021-01-20","2021-01-21","2021-01-22"]

},

{

type: 'category',

boundaryGap: true,

axisLabel: {

interval: 0,

rotate: 40

},

data: ["2020-12-28", "2020-12-29", "2020-12-30", "2020-12-31", "2021-01-01", "2021-01-02", "2021-01-03", "2021-01-04", "2021-01-05","2021-01-06" ,"2021-01-07","2021-01-08","2021-01-09","2021-01-10","2021-01-11","2021-01-12","2021-01-13","2021-01-14","2021-01-15","2021-01-16","2021-01-17","2021-01-18","2021-01-19","2021-01-20","2021-01-21","2021-01-22"]

}

],

yAxis: [{

type: 'value',

scale: true,

max: 37.5,

min: 35.5,

interval:0.1,

boundaryGap: [10, 10]

},

{

type: 'value',

scale: true,

max: 37.5,

min: 35.5,

interval:0.1,

boundaryGap: [10, 10]

}

],

series: [{

name: '体温',

type: 'bar',

xAxisIndex: 1,

yAxisIndex: 1,

barWidth:20,

itemStyle:{

normal:{

color:'#4c9d44'

}

},

data: [36.4, 36.3, 36.2, 36.4, 36.1, 36.5, 36.4, 36.7, 36.5, 36.7,36.6,36.7,36.95,36.85,36.7,36.5,36.5,36.7,36.4,36.3,36.3,36.35,36.1,36.55,36.5,36.45]

},

{

name: '体温',

type: 'line',

itemStyle:{

normal:{

color:'#e4393c',

lineStyle:{

color:'#e4393c'

}

}

},

data: [36.4, 36.3, 36.2, 36.4, 36.1, 36.5, 36.4, 36.7, 36.5, 36.7,36.6,36.7,36.95,36.85,36.7,36.5,36.5,36.7,36.4,36.3,36.3,36.35,36.1,36.55,36.5,36.45]

}

]

};

 

// 使用刚指定的配置项和数据显示图表。

chartBarLine.setOption(option);

},

chartLine() {

// 基于准备好的dom,初始化echarts实例

var chartLine = echarts.init(document.getElementById('chartLine'));

 

// 指定图表的配置项和数据

var option = {

tooltip: {

trigger: 'axis',

axisPointer: {

label: {

backgroundColor: '#283b56',

precision:0 //保留多少位

}

}

},

xAxis: {

max: 31,

min: 0,

interval:1,

//type : 'category'//没有小数点,也没有分割线了,而且位置居中不在刻度点上了。

},

yAxis: {

max: 37.5,

min: 35.5,

interval:0.1,

type : 'value'

},

series: [{

name: '体温',

type: 'line',

data: [[1,36.4], [2,36.3], [3,36.2],[4,36.4],[5,36.1],[6,36.5],[7,36.4],[8,36.7],[9,36.5],[10,36.7],[11,36.6],[12,36.7],[13,36.95],[14,36.85,],[15,36.7],[16,36.5],[17,36.5],[18,36.7],[19,36.4],[20,36.3],[21,36.3],[22,36.35],[23,36.1],[24,36.55],[25,36.5],[26,36.45]]

}]

};

 

// 使用刚指定的配置项和数据显示图表。

chartLine.setOption(option);

}

},

mounted() {

this.chartBarLine()

this.chartLine()

},

})

</script>

</body>

</html>

 

总结 

为了兼顾可读性,源码中保留了两个版本的图表。因为数据都是手写的,很可能出错,所以两个图表,也方便对照检查。

外部引用文件需要自行下载。

另,为了保护隐私,体温数据为假数据。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章