在Html中使用echarts图表


命令安装:npm install echarts --save

在index.html的<head></head>标签中引入echarts

  <script src="https://cdn.staticfile.org/echarts/4.3.0/echarts.min.js"></script>
  或者是在官网直接下载echarts.min.js文件在引入
 
在项目的入口文件man.js中
   import echarts from "echarts"
 
在需要用到的页面中创建实例
  
  <div id="myChart" ref="myChart" style="width: 600px;height:400px;"></div>
  
  var echarts = require('echarts');
 
    var myChart = echarts.init(document.getElementById('myChart'));
    // 指定图表的配置项和数据
    var option = {
      title: {
        text: '示例'
      },
      tooltip: {},
      legend: {
        data:['销量']
      },
      xAxis: {
        data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
      },
      yAxis: {},
      series: [{
        name: '销量',
        type: 'bar',
        data: [5, 20, 36, 10, 10, 20]
      }]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM