123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <template>
- <view class="charts-box">
- <qiun-data-charts type="pie" :eopts="opts" :chartData="chartData" :echartsH5="true" />
- </view>
- </template>
- <script>
- import {
- nowDate,
- timeToDate
- } from '../../utils/date.js'
- export default {
- props: {
- echartsData: Object
- },
- data() {
- return {
- chartData: {},
- //您可以通过修改 config-ucharts.js 文件中下标为 ['ring'] 的节点来配置全局默认参数,如都是默认参数,此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式,达到页面简洁的需求。
- opts: {
- tooltip: {
- trigger: 'item'
- },
- legend: {
- type: 'scroll',
- orient: 'horizontal',
- top: 'bottom'
- }
- },
- timeNum: 10,
- pieTime: null
- };
- },
- mounted() {
- this.getEmit()
- },
- beforeDestroy() {
- clearInterval(this.pieTime)
- this.pieTime = null
- },
- methods: {
- getServerData() {
- const chartData = this.echartsData.chartItemList[0]
- chartData.valueTimeList = chartData.valueTimeList.map(item => {
- return item.substring(0, this.timeNum)
- })
- const {
- valueList,
- valueTimeList
- } = chartData
- let data = valueTimeList.map((item, i) => {
- return {
- name: item,
- value: valueList[i]
- }
- })
- let chartDataPie = {
- "series": [{
- 'type': 'pie',
- radius: '55%',
- label: {
- show: false
- },
- data: data,
- center: ['50%', '30%']
- }]
- }
- this.chartData = chartDataPie
- },
- 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.pieTime = 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: 600rpx;
- }
- </style>
|