defendetail.js 2.5 KB
import * as echarts from '../../../ec-canvas/echarts';

const app = getApp();

function initChart(canvas, width, height) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height
  });
  canvas.setChart(chart);
  var colors = ['#5793f3', '#d14a61', '#675bba'];
  var option = {
    color: colors,

    tooltip: {
      trigger: 'none',
      axisPointer: {
        type: 'cross'
      }
    },
    legend: {
      data: ['每月','平均' ]
    },
    grid: {
      top: 70,
      bottom: 50
    },
    xAxis: [
      
      {
        type: 'category',
        axisTick: {
          alignWithLabel: true
        },
        axisLine: {
          onZero: false,
          lineStyle: {
            color: colors[1]
          },
         
        },
        axisPointer: {
          label: {
            formatter: function (params) {
              return '降水量  ' + params.value
                + (params.seriesData.length ? ':' + params.seriesData[0].data : '');
            }
          }
        },
        data: ["18.11", "18.12", "19.01", "19.02", "19.03", "19.04", "19.05", "19.06", "19.07"],
        axisLabel: {
          interval: 0,
        },
        smooth: true,
      },
      {
        type: 'category',
        axisTick: {
          alignWithLabel: true
        },
        axisLine: {
          onZero: false,
          lineStyle: {
            color: colors[0]
          }
        },
        axisPointer: {
          label: {
            formatter: function (params) {
              return '降水量  ' + params.value
                + (params.seriesData.length ? ':' + params.seriesData[0].data : '');
            }
          }
        },

      }
    ],
    yAxis: [
      {
        type: 'value',
        min:10,
        max:100,
        splitNumber: 10,

      }
    ],
    series: [
      {
        name: '平均',
        type: 'line',
        xAxisIndex: 1,
        smooth: true,
        data: [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 86.6, 96.2, 48.7, 18.8, 6.0, 2.3]
      },
      {
        name: '每月',
        type: 'line',
        smooth: true,
        data: [3.9, 5.9, 11.1, 18.7, 48.3, 69.2, 31.6, 46.6, 55.4, 18.4, 10.3, 0.7]
      }
    ]
  };

  chart.setOption(option);
  return chart;
}

Page({
  onShareAppMessage: function (res) {
    return {
      title: 'ECharts 可以在微信小程序中使用啦!',
      path: '/pages/index/index',
      success: function () { },
      fail: function () { }
    }
  },
  data: {
    ec: {
      onInit: initChart
    }
  },

  onReady() { }
});