angularjs引入echarts包_angularjs实现echart图表效果最简洁教程

一 echart包引用

下载解压,放入lib中。

链接: https://pan.baidu.com/s/1dEMKXGl 密码: s6c3

并在index.html中引用如图两个js文件。

引用包.png

app.js中引用angular-echarts

image.png

二 页面

html页面

controller

/**

* Created by xiehan on 2017/11/29.

*/

angular.module('studyApp.controllers')

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

$scope.title = 'echart图表';

/*

官方实例链接: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, '50%'],

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: 'echart饼图测试',

datapoints: temp2

}];

}

}

//柱状图数据

function initConfigChart() {

var parkaccountChart = echarts.init(document.getElementById('id0001'));//div 标签id

var seriesLabel = {

normal: {

show: true,

textBorderColor: '#333',

textBorderWidth: 2

}

};

var option = {

tooltip: {

trigger: 'axis',

axisPointer: {

type: 'shadow'

}

},

legend: {

data: ['总数1', '总数2', '总数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: '总数1',

type: 'bar',

label: seriesLabel,

data: [165, 170, 330]

},

{

name: '总数2',

type: 'bar',

label: seriesLabel,

data: [150, 105, 110]

},

{

name: '总数3',

type: 'bar',

label: seriesLabel,

data: [220, 82, 63]

}

]

};

parkaccountChart.setOption(option);

}

});

效果图

效果图.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值