123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- // 线图
- import * as echarts from '../../ec-canvas/echarts';
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- canvasId: {
- type: String,
- value: "mychart-dom-bar"
- },
- id: {
- type: String,
- value: "mychart-bar"
- },
- type: {
- type: String,
- value: "bar"
- },
- select: {
- type: String,
- value: ""
- },
- btnList: {
- type: Array,
- value: [],
- },
- color: {
- type: String,
- value: ""
- },
- isShow: {
- type: Boolean,
- value: false,
- observer: function (n) {
- const select = this.data.select === '6m' || this.data.select === '24h';
- if (!select) return
- console.log("需要更新");
- if (n) this.triggerEvent("lineChenge", this.data.select);
- }
- },
- list: {
- type: Array,
- value: [],
- observer: function (n, o) {
- if (!n || !n.length) return;
- if (this.data.select !== '24h' && this.data.select !== '6m' && this.setInterval) clearInterval(this.setInterval)
- if (this.data.select !== '24h' && this.data.select !== '6m' && this.setTimeout) clearInterval(this.setTimeout)
- let xData = [], yData = [], color = this.data.color || "24,144,255";
- yData = {
- type: this.data.type,
- smooth: 0.6,
- symbolSize: 1,
- itemStyle: {
- color: "rgba(" + color + ", 1)"
- },
- lineStyle: {
- width: 1
- },
- areaStyle: {
- color: new echarts.graphic.LinearGradient(
- 0, 0, 0, 1,
- [
- { offset: 0, color: 'rgba(' + color + ', .8)' },
- { offset: 1, color: 'rgba(' + color + ', 0)' },
- ]
- )
- },
- data: []
- }
- n.map((v, i) => {
- yData.data.push(v[this.data.yType]);
- xData.push(v[this.data.xType])
- })
- if (this.chart) {
- const option = this.chart.getOption();
- option.series = yData;
- option.xAxis[0].data = xData;
- option.series = yData;
- this.chart.setOption(option);
- this.setData({
- xData,
- yData,
- show: true
- })
- } else {
- this.setData({
- ec: {
- onInit: this.initChart.bind(this)
- },
- xData,
- yData,
- show: true
- })
- }
- }
- },
- yType: {
- type: String,
- value: ""
- },
- xType: {
- type: String,
- value: ""
- }
- },
- chart: undefined,
- setInterval: undefined,
- setTimeout: undefined,
- ready() {
- wx.setStorageSync('nextTime', 0)
- },
- // 销毁组件
- detached: function () {
- this.chart && this.chart.dispose && this.chart.dispose();
- this.setInterval && clearInterval(this.setInterval);
- this.setTimeout && clearInterval(this.setTimeout);
- },
- /**
- * 组件的初始数据
- */
- data: {
- show: false,
- ec: {
- onInit: undefined
- },
- xData: [],
- yData: [],
- },
- /**
- * 组件的方法列表
- */
- methods: {
- initChart: function (canvas, width, height, dpr) {
- this.chart && this.chart.dispose && this.chart.dispose();
- this.chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr // 像素
- });
- canvas.setChart(this.chart);
- var option = {
- animation: false,
- tooltip: {
- show: true,
- textStyle: {
- color: "#fff"
- },
- backgroundColor: 'rgba(0,0,0,.5)',
- trigger: 'axis',
- axisPointer: { // 坐标轴指示器,坐标轴触发有效
- type: 'line', // 默认为直线,可选为:'line' | 'shadow'
- shadowStyle: {
- color: "rgba(150,150,150,0.2)"
- },
- },
- formatter: "{b}\n{c}",
- },
- color: ['#1890ff'],
- grid: {
- top: "10px",
- left: '3%',
- right: '4%',
- bottom: '3%',
- containLabel: true
- },
- xAxis: {
- interval: 0,
- type: 'category',
- boundaryGap: false,
- data: this.data.xData,
- splitLine: { show: false },
- axisTick: {
- show: false
- },
- axisLine: {
- show: false,
- lineStyle: {
- color: '#bfcbd9',
- }
- }
- },
- yAxis: {
- type: 'value',
- splitLine: { show: true, lineStyle: { type: "dotted", color: '#4e5358' } },
- axisLine: {
- show: false,
- lineStyle: {
- color: '#bfcbd9',
- }
- },
- axisLabel: {
- formatter: function (val, index) {
- let out = val;
- if (val >= 1000 && val < 10000) {
- out = (val / 1000).toFixed(2) - 0 + "千"
- } else if (val >= 10000 && val < 100000000) {
- out = (val / 10000).toFixed(0) - 0 + "万"
- } else if (val >= 100000000) {
- out = (val / 100000000).toFixed(2) - 0 + "亿"
- }
- return out
- }
- }
- },
- series: this.data.yData
- };
- this.chart.setOption(option);
- return this.chart;
- },
- changeselect: function (e) {
- let type = e.currentTarget.dataset.type;
- if (type === this.data.select) return;
- this.setInterval && clearInterval(this.setInterval);
- this.setTimeout && clearInterval(this.setTimeout);
- if (type === '24h' || type === '6m') this.countFun(type);
- this.triggerEvent("lineChenge", type)
- },
- countFun(type) {
- let time = new Date();
- let min = time.getMinutes();
- let remainder = min % 10;
- if (remainder === 1) {
- this.setInterval = setInterval(() => {
- console.log("定时")
- this.triggerEvent("lineChenge", type);
- }, 600000)
- } else {
- this.setTimeout = setTimeout(() => {
- clearTimeout(this.setTimeout);
- this.triggerEvent("lineChenge", type);
- this.setInterval = setInterval(() => {
- console.log("定时")
- this.triggerEvent("lineChenge", type);
- }, 600000)
- }, (11 - remainder) * 1000 * 60);
- }
- }
- }
- })
|