123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- <template>
- <view class="charts-box">
- <qiun-data-charts :eopts="opts" :chartData="chartData" :echartsH5="true" tooltipFormat="lineDemo" />
- </view>
- </template>
- <script>
- import {
- nowDate,
- timeToDate
- } from '../../utils/date.js';
- export default {
- props: {
- echartsData: Object
- },
- data() {
- return {
- chartData: {},
- //您可以通过修改 config-ucharts.js 文件中下标为 ['line'] 的节点来配置全局默认参数,如都是默认参数,此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式,达到页面简洁的需求。
- opts: {
- color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
- "#ea7ccc"
- ],
- padding: [15, 10, 0, 15],
- legend: {
- type: 'scroll',
- pageIconSize: 18,
- margin: 20,
- itemGap: 20,
- lineHeight: 20,
- top: 0,
- },
- grid: {
- bottom: '25%',
- top: "50px",
- left: "45px",
- right: "30px"
- },
- xAxis: {
- type: 'category',
- axisLabel: {
- interval: 60, // 自定义显示X轴坐标显示间隔
- textStyle: {
- color: '#626262',
- fontSize: '10',
- },
- format:(value, index)=> {
- console.log(value)
- return value + 'kg';
- }
- }
- },
- yAxis: {
- type: 'value',
- // axisPointer: {
- // snap: true,
- // show: true,
- // type: 'line',
- // lineStyle: {
- // color: 'rgba(98, 98, 98, 0.7)',
- // type: 'solid'
- // }
- // }
- },
- // tooltip: {
- // trigger: 'axis',
- // axisPointer: {
- // type: 'cross',
- // label: {
- // show: false,
- // backgroundColor: 'rgba(98, 98, 98, 0.8)'
- // }
- // },
- // backgroundColor: 'rgba(50,50,50,0.5)'
- // },
- dataZoom: [
- // {
- // type: 'slider',
- // show: true,
- // xAxisIndex: [0],
- // start: 90,
- // end: 100,
- // },
- // {
- // type: 'slider',
- // show: true,
- // yAxisIndex: [0],
- // left: '93%',
- // start: 60,
- // end: 100
- // },
- {
- type: 'inside',
- xAxisIndex: [0],
- start: 85,
- end: 100
- // preventDefaultMouseMove: false
- },
- // {
- // type: 'inside',
- // yAxisIndex: [0],
- // start: 60,
- // end: 100
- // },
- ]
- },
- timeNum: 10,
- lineTime: null,
- };
- },
- mounted() {
- this.getEmit();
- },
- beforeDestroy() {
- clearInterval(this.lineTime)
- this.lineTime = null
- },
- methods: {
- getServerData() {
- const chartData = this.echartsData.chartItemList
- const timeData = chartData[0].valueTimeList
- const time = timeData.map(item => {
- return item.substring(0, 19).replaceAll('-', "")
- })
- const series = chartData.map(item => {
- // let valueList=[];
- // item.valueList.forEach(o=>{
- // valueList.push(o.split(""))
- // })
- return {
- type: 'line',
- name: item.describe ? item.describe : item.itemName,
- data: item.valueList
- }
- })
- this.opts.xAxis.data = time
- let res = {
- categories: time,
- series: series
- };
- this.chartData = JSON.parse(JSON.stringify(res));
- },
- getEmit() {
- const {
- bucketType,
- bucketValue
- } = this.echartsData
- let time = null
- switch (bucketType) {
- case 0:
- time = 86400000 * bucketValue
- this.timeNum = 4
- break;
- case 1:
- time = 3600000 * bucketValue
- this.timeNum = 13
- break;
- case 2:
- time = 60000 * bucketValue
- this.timeNum = 16
- break;
- case 3:
- time = 1000 * bucketValue
- this.timeNum = 19
- break;
- }
- this.getServerData()
- this.lineTime = setInterval(() => {
- let chartParams = {
- id: this.echartsData.id,
- startTime: timeToDate(new Date().getTime() - 3600000),
- endTime: nowDate()
- }
- uni.$http.get('/chart/getChartById', chartParams).then(res => {
- })
- }, time)
- }
- }
- };
- </script>
- <style scoped>
- /* 请根据实际需求修改父元素尺寸,组件自动识别宽高 */
- .charts-box {
- width: 100%;
- height: 540rpx;
- }
- </style>
|