美文网首页给自己看的IT
在ionic2中使用echarts

在ionic2中使用echarts

作者: 美味小鱼 | 来源:发表于2017-05-26 17:14 被阅读138次

安装包 echarts

npm install echarts --save
npm install @types/echarts --save

使用echarts

html文件中添加了用id绑定的div

然后在ts文件中import echarts

createCharts() {
    var myChart = ECharts.init(document.getElementById('tu') as HTMLDivElement);
    // 指定图表的配置项和数据
    var option = {
      title: {
        text: 'ECharts 入门示例'
      },
      tooltip: {},
      legend: {
        data: ['销量']
      },
      xAxis: {
        data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
      },
      yAxis: {},
      series: [{
        name: '销量',
        type: 'bar',
        data: [5, 20, 36, 10, 10, 20]
      }]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
  }
<div style="width:100%;height:300px" id='tu'>                                                                                  
 </div>  

如果需要宽度自适应,在width的设置上使用百分比

import ECharts from 'echarts';

网上抄的一个自适应宽度的指令

import { Directive, ElementRef, Renderer } from '@angular/core';

@Directive({
    selector: '[autofit]'
})
export class AutoFitLayout {
    constructor(public element: ElementRef, public renderer: Renderer) {
        //因为ionic的默认padding宽度是16
        renderer.setElementStyle(element.nativeElement, 'width', `${(document.body.clientWidth - 32).toString()}px`);
    }
}

这个指令的问题在于,如果平板端使用了splitpane的话,获取到的宽度就不正常了.在手机窄屏的情况下没有问题,如果宽屏就用百分比来实现好了.

image.png

有高手知道如何改进这个指令的,希望不吝赐教.

相关文章

  • 在ionic2中使用echarts

    安装包 echarts 使用echarts 在html文件中添加了用id绑定的div 然后在ts文件中import...

  • Vue项目中使用Echarts

    Echarts 官网 安装Echats 使用 在main.js中引入Echarts 在模板中加入挂载Echarts...

  • echarts-for-react

    简介 使用echarts-for-react插件可以在React中调用echarts接口直接渲染出Echarts图...

  • vue中使用Echarts

    一、vue中简单使用Echarts 步骤1:安装echarts安装包 步骤2:引入依赖 (在需要使用的组件中) 步...

  • 小程序使用Echars

    一、微信中使用 Echars直接在官网小程序使用Echarts中(文档-教程-在微信中使用Echarts),找到G...

  • ionic2/3实战-使用ECharts

    ECharts API ECharts demo 安装 使用 在页面上放一个div作为图标容器 ts 效果 这里只...

  • vue2.0使用echarts入门

    1.在vue2.0中使用echarts需要通过npm进行安装npm install echarts --save2...

  • echarts 和 ionic2 交互

    点击echarts 的图像时候,获取点击区域的数据,传递给ionic2的导航函数 点击的时候获取 params

  • Echarts 使用问题小结

    因为在项目开发中主要使用Echarts来做可视化图表,本文主要收集汇总一些Echarts使用中的问题解决小集。 t...

  • 2018-09-05

    在ionic2中使用ionic cordova build android 命令时出现以下错误: * What w...

网友评论

    本文标题:在ionic2中使用echarts

    本文链接:https://www.haomeiwen.com/subject/hlyxfxtx.html