123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- // 线图
- import * as echarts from '../../ec-canvas/echarts';
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- canvasId: {
- type: String,
- value: "mychart-dom-bar"
- },
- id: {
- type: String,
- value: "mychart-bar"
- },
- showLegend:{
- type: Boolean,
- value: true
- },
- list: {
- type: Array,
- value: [],
- observer: function (n, o) {
- if (!n || !n.length) return;
- if (this.chart) {
- const option = this.chart.getOption();
- option.series = n;
- this.chart.setOption(option);
- } else {
- this.setData({
- ec: {
- onInit: this.initChart.bind(this)
- }
- })
- }
- }
- },
- yType: {
- type: String,
- value: ""
- },
- xType: {
- type: String,
- value: ""
- }
- },
- chart: undefined,
- ready() {
- this.setData({
- ec: {
- onInit: this.initChart.bind(this)
- }
- })
- },
- // 销毁组件
- detached: function () {
- this.chart && this.chart.dispose && this.chart.dispose();
- },
- /**
- * 组件的初始数据
- */
- data: {
- ec: {
- onInit: undefined,
- lazyload: true
- },
- },
- /**
- * 组件的方法列表
- */
- 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);
- // let colorList = ['9','a','b','c','d','e','f'], len = (this.data.list[0].data || []).length, colors = [];
- // for (let i = 0; i < len; i++) {
- // let color = "#";
- // for (let o = 0; o < 6; o++) {
- // color += colorList[Math.floor(Math.random()*7)]
- // }
- // colors.push(color);
- // }
- var option = {
- tooltip: {
- trigger: 'item',
- formatter: '{b}{d}%',
- position: [0, "90%"],
- textStyle: {
- color: "#fff"
- },
- },
- legend: {
- show: this.data.showLegend,
- left: 'left',
- itemGap: 1,
- itemWidth:4,
- itemHeight:4,
- textStyle: {
- color: "#fff"
- }
- },
- color: ["#dd79ff","#58d9f9"],
- // color: colors,
- series: this.data.list || []
- };
- this.chart.setOption(option);
- this.setData({
- show: true
- })
- return this.chart;
- },
- }
- })
|