Home > Web Front-end > JS Tutorial > A simple tutorial to implement echart chart effect in angularjs

A simple tutorial to implement echart chart effect in angularjs

小云云
Release: 2017-12-12 10:37:12
Original
2194 people have browsed it

ehcart is a data chart made by Baidu, based on native js. The interface and configuration are well written and easy to read, and can also be used for commercial purposes. This article mainly introduces the most concise tutorial that explains the effect of echart chart in angularjs. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor to take a look, I hope it can help everyone.

1 echart package reference

Download, unzip and put it into lib.

Download address: echart_jb51.rar

And reference the two js files as shown in the index.html.

Quote angular-echarts in app.js

##Second page

html page

<!--饼图-->
  <p>
   <donut-chart config="donutConfig" data="dataList.incomeData">
   </donut-chart>
  </p>
Copy after login

<!--柱状图-->
 <p id="id0001" style="width: 100%;height: 400px; padding: 0;margin: 0; border-width: 0; ">
 </p>
Copy after login

controller

/**
 * Created by xiehan on 2017/11/29.
 */
angular.module(&#39;studyApp.controllers&#39;)

 .controller(&#39;EchartCtrl&#39;, function ($scope, $rootScope, $ionicHistory,$location) {

  $scope.title = &#39;echart图表&#39;;

  /*
   官方实例链接:http://echarts.baidu.com/examples.html
   */

  $scope.goBack = function () {
   $ionicHistory.goBack();
  };

  //用于数据的格式化
  $scope.dataList = {
   incomeData:""
  };
  // 饼图
  $scope.pieConfig = {};
  // 环形图
  $scope.donutConfig = {};

  init();

  function init() {
   initChartsConfig();
   initIncome();
   initConfigChart();
  }

  //饼图配置初始化
  function initChartsConfig() {
   $scope.pieConfig = {
    center: [120, &#39;50%&#39;],
    radius: 90
   };
   $scope.donutConfig = {
    radius: [0, 90]
   };
  }
  //饼图数据
  function initIncome(){
   var temp = [
    {
     NAME:"测试1",
     NUM:11
    },
    {
     NAME:"测试2",
     NUM:22
    },
    {
     NAME:"测试3",
     NUM:33
    },
    {
     NAME:"测试4",
     NUM:44
    }
   ];

   if (temp) {
    // 处理数据
    var temp2 = [];
    angular.forEach(temp, function (item) {
     var t = {x: item.NAME, y: item.NUM};
     temp2.push(t);
    });
    $scope.dataList.incomeData = [{
     name: &#39;echart饼图测试&#39;,
     datapoints: temp2
    }];
   }
  }

  //柱状图数据
  function initConfigChart() {
   var parkaccountChart = echarts.init(document.getElementById(&#39;id0001&#39;));//p 标签id
   var seriesLabel = {
    normal: {
     show: true,
     textBorderColor: &#39;#333&#39;,
     textBorderWidth: 2
    }
   };
   var option = {
    tooltip: {
     trigger: &#39;axis&#39;,
     axisPointer: {
      type: &#39;shadow&#39;
     }
    },
    legend: {
     data: [&#39;总数1&#39;, &#39;总数2&#39;, &#39;总数3&#39;],
     bottom:true
    },
    grid: {
     left: &#39;1%&#39;,
     right: &#39;4%&#39;,
     bottom: &#39;8%&#39;,
     top:&#39;5%&#39;,
     containLabel: true
    },
    xAxis: {
     type: &#39;value&#39;,
     name: &#39;&#39;,
     axisLabel: {
      formatter: &#39;{value}&#39;
     }
    },
    yAxis: {
     type: &#39;category&#39;,
     inverse: true,
     data: [&#39;y1&#39;, &#39;y2&#39;, &#39;y3&#39;]
    },
    series: [
     {
      name: &#39;总数1&#39;,
      type: &#39;bar&#39;,
      label: seriesLabel,
      data: [165, 170, 330]
     },
     {
      name: &#39;总数2&#39;,
      type: &#39;bar&#39;,
      label: seriesLabel,
      data: [150, 105, 110]
     },
     {
      name: &#39;总数3&#39;,
      type: &#39;bar&#39;,
      label: seriesLabel,
      data: [220, 82, 63]
     }
    ]
   };
   parkaccountChart.setOption(option);

  }

 });
Copy after login

Rendering

Related recommendations:


Parsing parameters of angularjs array Method

Summary of how angularjs handles multiple asynchronous requests

Summary of common knowledge for getting started with AngularJS

The above is the detailed content of A simple tutorial to implement echart chart effect in angularjs. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template