溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

angularjs實(shí)現(xiàn)echart圖表效果最簡(jiǎn)潔教程

發(fā)布時(shí)間:2021-04-21 10:44:33 來(lái)源:億速云 閱讀:401 作者:小新 欄目:web開(kāi)發(fā)

小編給大家分享一下angularjs實(shí)現(xiàn)echart圖表效果最簡(jiǎn)潔教程,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!

js的作用是什么

1、能夠嵌入動(dòng)態(tài)文本于HTML頁(yè)面。2、對(duì)瀏覽器事件做出響應(yīng)。3、讀寫(xiě)HTML元素。4、在數(shù)據(jù)被提交到服務(wù)器之前驗(yàn)證數(shù)據(jù)。5、檢測(cè)訪客的瀏覽器信息。6、控制cookies,包括創(chuàng)建和修改等。7、基于Node.js技術(shù)進(jìn)行服務(wù)器端編程。

具體如下:

ehcart是百度做的數(shù)據(jù)圖表,基于原生js。接口和配置都寫(xiě)的很好很易讀,還可以用于商用。

一 echart包引用

下載解壓,放入lib中。

下載地址:echart_jb51.rar

并在index.html中引用如圖兩個(gè)js文件。

angularjs實(shí)現(xiàn)echart圖表效果最簡(jiǎn)潔教程

app.js中引用angular-echarts

angularjs實(shí)現(xiàn)echart圖表效果最簡(jiǎn)潔教程

二 頁(yè)面

html頁(yè)面

<!--餅圖-->
  <div>
   <donut-chart config="donutConfig" data="dataList.incomeData">
   </donut-chart>
  </div>
<!--柱狀圖-->
 <div id="id0001" >
 </div>

controller

/**
 * Created by xiehan on 2017/11/29.
 */
angular.module('studyApp.controllers')

 .controller('EchartCtrl', function ($scope, $rootScope, $ionicHistory,$location) {

  $scope.title = 'echart圖表';

  /*
   官方實(shí)例鏈接:http://echarts.baidu.com/examples.html
   */

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

  //用于數(shù)據(jù)的格式化
  $scope.dataList = {
   incomeData:""
  };
  // 餅圖
  $scope.pieConfig = {};
  // 環(huán)形圖
  $scope.donutConfig = {};

  init();

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

  //餅圖配置初始化
  function initChartsConfig() {
   $scope.pieConfig = {
    center: [120, '50%'],
    radius: 90
   };
   $scope.donutConfig = {
    radius: [0, 90]
   };
  }
  //餅圖數(shù)據(jù)
  function initIncome(){
   var temp = [
    {
     NAME:"測(cè)試1",
     NUM:11
    },
    {
     NAME:"測(cè)試2",
     NUM:22
    },
    {
     NAME:"測(cè)試3",
     NUM:33
    },
    {
     NAME:"測(cè)試4",
     NUM:44
    }
   ];

   if (temp) {
    // 處理數(shù)據(jù)
    var temp2 = [];
    angular.forEach(temp, function (item) {
     var t = {x: item.NAME, y: item.NUM};
     temp2.push(t);
    });
    $scope.dataList.incomeData = [{
     name: 'echart餅圖測(cè)試',
     datapoints: temp2
    }];
   }
  }

  //柱狀圖數(shù)據(jù)
  function initConfigChart() {
   var parkaccountChart = echarts.init(document.getElementById('id0001'));//div 標(biāo)簽id
   var seriesLabel = {
    normal: {
     show: true,
     textBorderColor: '#333',
     textBorderWidth: 2
    }
   };
   var option = {
    tooltip: {
     trigger: 'axis',
     axisPointer: {
      type: 'shadow'
     }
    },
    legend: {
     data: ['總數(shù)1', '總數(shù)2', '總數(shù)3'],
     bottom:true
    },
    grid: {
     left: '1%',
     right: '4%',
     bottom: '8%',
     top:'5%',
     containLabel: true
    },
    xAxis: {
     type: 'value',
     name: '',
     axisLabel: {
      formatter: '{value}'
     }
    },
    yAxis: {
     type: 'category',
     inverse: true,
     data: ['y1', 'y2', 'y3']
    },
    series: [
     {
      name: '總數(shù)1',
      type: 'bar',
      label: seriesLabel,
      data: [165, 170, 330]
     },
     {
      name: '總數(shù)2',
      type: 'bar',
      label: seriesLabel,
      data: [150, 105, 110]
     },
     {
      name: '總數(shù)3',
      type: 'bar',
      label: seriesLabel,
      data: [220, 82, 63]
     }
    ]
   };
   parkaccountChart.setOption(option);

  }

 });

效果圖

angularjs實(shí)現(xiàn)echart圖表效果最簡(jiǎn)潔教程

看完了這篇文章,相信你對(duì)“angularjs實(shí)現(xiàn)echart圖表效果最簡(jiǎn)潔教程”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI