詳解angularjs實(shí)現(xiàn)echart圖表效果最簡(jiǎn)潔教程
本文介紹了詳解angularjs實(shí)現(xiàn)echart圖表效果最簡(jiǎn)潔教程,分享給大家,具體如下:
ehcart是百度做的數(shù)據(jù)圖表,基于原生js。接口和配置都寫(xiě)的很好很易讀,還可以用于商用。
一 echart包引用
下載解壓,放入lib中。
下載地址:echart_jb51.rar
并在index.html中引用如圖兩個(gè)js文件。
app.js中引用angular-echarts
二 頁(yè)面
html頁(yè)面
<!--餅圖--> <div> <donut-chart config="donutConfig" data="dataList.incomeData"> </donut-chart> </div>
<!--柱狀圖--> <div id="id0001" style="width: 100%;height: 400px; padding: 0;margin: 0; border-width: 0; "> </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); } });
效果圖
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Angular2.0/4.0 使用Echarts圖表的示例代碼
- Angular實(shí)現(xiàn)svg和png圖片下載實(shí)現(xiàn)
- Angular中實(shí)現(xiàn)樹(shù)形結(jié)構(gòu)視圖實(shí)例代碼
- Angular.js與Bootstrap相結(jié)合實(shí)現(xiàn)表格分頁(yè)代碼
- 詳解AngularJS中的表格使用
- AngularJS實(shí)現(xiàn)表格的增刪改查(僅限前端)
- angularjs表格ng-table使用備忘錄
- 最棒的Angular2表格控件
- 使用angularjs創(chuàng)建簡(jiǎn)單表格
- Angular2使用SVG自定義圖表(條形圖、折線圖)組件示例
相關(guān)文章
Angularjs 制作購(gòu)物車(chē)功能實(shí)例代碼
這篇文章主要介紹了Angularjs 制作購(gòu)物車(chē)功能實(shí)例代碼的相關(guān)資料,并附示例代碼,需要的朋友可以參考下2016-09-09AngularJS深入探討scope,繼承結(jié)構(gòu),事件系統(tǒng)和生命周期
這篇文章主要介紹了AngularJS的scope,繼承結(jié)構(gòu),事件系統(tǒng)和生命周期,較為詳細(xì)的分析了scope的作用域、層次結(jié)構(gòu)、繼承及生命周期相關(guān)概念與使用技巧,需要的朋友可以參考下2016-11-11AngularJS實(shí)現(xiàn)自定義指令及指令配置項(xiàng)的方法
這篇文章主要介紹了AngularJS實(shí)現(xiàn)自定義指令及指令配置項(xiàng)的方法,結(jié)合實(shí)例形式簡(jiǎn)單總結(jié)分析了AngularJS自定義指令及指令配置項(xiàng)的實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-11-11AngularJs unit-testing(單元測(cè)試)詳解
本文主要介紹AngularJs unit-testing(單元測(cè)試)的內(nèi)容,這里整理了單元測(cè)試的知識(shí),及示例代碼,有興趣的朋友可以參考下2016-09-09Angular 4.x 動(dòng)態(tài)創(chuàng)建表單實(shí)例
本篇文章主要介紹了Angular 4.x 動(dòng)態(tài)創(chuàng)建表單實(shí)例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-04-04AngularJS入門(mén)教程之Cookies讀寫(xiě)操作示例
這篇文章主要介紹了AngularJS的Cookies讀寫(xiě)操作,結(jié)合實(shí)例形式分析了ngCookies模塊與get和put方法進(jìn)行cookie讀寫(xiě)操作的相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-11-11Material(包括Material Icon)在Angular2中的使用詳解
這篇文章主要介紹了Material(包括Material Icon)在Angular2中的使用,需要的朋友可以參考下2018-02-02