 悬赏园豆:50
                [已关闭问题] 
            
                    关闭于 2020-06-27 11:04
                悬赏园豆:50
                [已关闭问题] 
            
                    关闭于 2020-06-27 11:04
                 
        首先在pages文件夹下创建了line文件夹并创建了index.js/.json/.wxml/.wxxs
已在app.json文件写入"pages/line/index"
在line文件夹中的index.js文件
import * as echarts from '../../ec-canvas/echarts';
const app = getApp();
function initChart(canvas, width, height, dpr) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr // new
  });
  canvas.setChart(chart);
  var option = {
    title: {
      text: '测试下面legend的红色区域不应被裁剪',
      left: 'center'
    },
    color: ["#37A2DA", "#67E0E3", "#9FE6B8"],
    legend: {
      data: ['A', 'B', 'C'],
      top: 50,
      left: 'center',
      backgroundColor: 'red',
      z: 100
    },
    grid: {
      containLabel: true
    },
    tooltip: {
      show: true,
      trigger: 'axis'
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
      // show: false
    },
    yAxis: {
      x: 'center',
      type: 'value',
      splitLine: {
        lineStyle: {
          type: 'dashed'
        }
      }
      // show: false
    },
    series: [{
      name: 'A',
      type: 'line',
      smooth: true,
      data: [18, 36, 65, 30, 78, 40, 33]
    }, {
      name: 'B',
      type: 'line',
      smooth: true,
      data: [12, 50, 51, 35, 70, 30, 20]
    }, {
      name: 'C',
      type: 'line',
      smooth: true,
      data: [10, 30, 31, 50, 40, 20, 10]
    }]
  };
  chart.setOption(option);
  return chart;
}
Page({
 
  data: {
    ec: {
      onInit: initChart
    }
  },
  onReady() {
  }
});
在line文件夹中的index.json文件
{
  "usingComponents": {
    "ec-canvas": "../../ec-canvas/ec-canvas"
  }
}
在line文件夹中的index.wxml文件
<!--index.wxml-->
<view class="container">
  <ec-canvas id="mychart-dom-line" canvas-id="mychart-line" ec="{{ ec }}"></ec-canvas>
</view>
在line文件夹中的index.wxss文件
/**index.wxss**/
ec-canvas {
  width: 100%;
  height: 100%;
}
可是编译后界面显示空白 是我配置哪里有错误吗
官方例程的readme中看到了
注意此处的 .container,新建小程序项目后,其中 app.wxss 中默认自动生成的此 class 与本 demo 中的可能不一致,导致图表不能正常显示,只显示空白。请注意参考 app.wxss 修改样式,保证图表的初始化的时候是有宽度和高度的。
把官方的app.wxss中的.container 代码粘贴到我的app.wxss就可以正常显示了