Angular Google Charts教程_编程入门自学教程_菜鸟教程-免费教程分享 Posted 2023-06-07 itbanzuan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Angular Google Charts教程_编程入门自学教程_菜鸟教程-免费教程分享相关的知识,希望对你有一定的参考价值。
教程简介
Google Charts 是一个纯粹的基于JavaScript的图表库,旨在通过添加交互式图表功能来增强Web应用程序.它支持各种图表.在Chrome,Firefox,Safari,Internet Explorer(IE)等标准浏览器中使用SVG绘制图表.在传统的IE 6中,VML用于绘制图形.
Angular Google Charts 是一个基于开源角度的Google图表包装,提供优雅并且在Angular应用程序中具有丰富的Google Charts可视化功能,并且可以与Angular组件无缝地一起使用.
Angular Google Charts入门教程 - 从基本到高级概念的简单步骤熟悉Angular Google Charts,其中包括概述,环境设置,配置语法,区域图表,条形图,气泡图,烛台图表,柱形图,组合图表,直方图,折线图,地图,组织结构图,饼图,Sankey图,散点图,阶梯图,表格图,树图。
教程目录
Angular Google Charts教程
Angular Google Charts - 概述
Angular Google Charts - 环境设置
Angular Google Charts - 配置语法
Angular Google Charts - 区域图表
Angular Google Charts - 条形图
Angular Google Charts - 气泡图
Angular Google Charts - 烛台图表
Angular Google Charts - 列图表
Angular Google Charts - 组合图表
Angular Google Charts - 直方图
Angular Google Charts - 折线图
Angular Google Charts - 地图图表
Angular Google Charts - 组织结构图
Angular Google Charts - 饼图
Angular Google Charts - Sankey Charts
Angular Google Charts - 散点图
Angular Google Charts - 阶梯式图表
Angular Google Charts - 表格图表
Angular Google Charts - 树形图
Angular Google Charts - 有用的资源
markdown Google Charts实验
@import url(https://fonts.googleapis.com/css?family=Open+Sans:400,700);
body {
font-family: "Open Sans", Arial;
background: #EDEDED;
}
main {
width: 800px;
margin: 10px auto;
padding: 10px 20px 30px;
background: #FFF;
box-shadow: 0 3px 5px rgba(0,0,0,0.2);
}
p {
margin-top: 2rem;
font-size: 13px;
}
#bar-chart {
width: 800px;
height: 300px;
position: relative;
}
#line-chart {
width: 800px;
height: 300px;
position: relative;
}
#bar-chart::before, #line-chart::before {
content: "";
position: absolute;
display: block;
width: 240px;
height: 30px;
left: 305px;
top: 254px;
background: #FAFAFA;
box-shadow: 2px 2px 5px 0 #DDD;
}
#pie-chart {
width: 800px;
height: 250px;
position: relative;
}
#pie-chart::before {
content: "";
position: absolute;
display: block;
width: 120px;
height: 115px;
left: 505px;
top: 0;
background: #FAFAFA;
box-shadow: 2px 2px 5px 0 #DDD;
}
#pie-chart::after {
content: "";
position: absolute;
display: block;
top: 260px;
left: 160px;
width: 170px;
height: 2px;
background: rgba(0,0,0,0.1);
border-radius: 50%;
box-shadow: 0 0 3px 4px rgba(0,0,0,0.1);
}
<script src="https://www.google.com/jsapi"></script>
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawCharts);
function drawCharts() {
// actual bar chart data
var barData = google.visualization.arrayToDataTable([
['Day', 'Page Views', 'Unique Views'],
['Sun', 1050, 600],
['Mon', 1370, 910],
['Tue', 660, 400],
['Wed', 1030, 540],
['Thu', 1000, 480],
['Fri', 1170, 960],
['Sat', 660, 320]
]);
// set bar chart options
var barOptions = {
focusTarget: 'category',
backgroundColor: 'transparent',
colors: ['#339891', '#ff8282'],
fontName: 'Open Sans',
chartArea: {
left: 50,
top: 10,
width: '100%',
height: '70%'
},
bar: {
groupWidth: '100%'
},
hAxis: {
textStyle: {
fontSize: 11
}
},
vAxis: {
minValue: 0,
maxValue: 1500,
baselineColor: '#6ad4cd',
gridlines: {
color: '#6ad4cd',
count: 4
},
textStyle: {
fontSize: 11
}
},
legend: {
position: 'bottom',
textStyle: {
fontSize: 12
}
},
animation: {
duration: 1200,
easing: 'out',
startup: true
}
};
// draw bar chart twice so it animates
var barChart = new google.visualization.ColumnChart(document.getElementById('bar-chart'));
barChart.draw(barData, barOptions);
// BEGIN LINE GRAPH
function randomNumber(base, step) {
return Math.floor((Math.random()*step)+base);
}
function createData(year, start1, start2, step, offset) {
var ar = [];
for (var i = 0; i < 12; i++) {
ar.push([new Date(year, i), randomNumber(start1, step)+offset, randomNumber(start2, step)+offset]);
}
return ar;
}
var randomLineData = [
['Year', 'Page Views', 'Unique Views']
];
for (var x = 0; x < 7; x++) {
var newYear = createData(2007+x, 10000, 5000, 4000, 800*Math.pow(x,2));
for (var n = 0; n < 12; n++) {
randomLineData.push(newYear.shift());
}
}
var lineData = google.visualization.arrayToDataTable(randomLineData);
var lineOptions = {
backgroundColor: 'transparent',
colors: ['#339891', '#ff8282'],
fontName: 'Open Sans',
focusTarget: 'category',
chartArea: {
left: 50,
top: 10,
width: '100%',
height: '70%'
},
curveType: 'function', // smooth curve lines
hAxis: {
//showTextEvery: 12,
textStyle: {
fontSize: 11
},
baselineColor: 'transparent',
gridlines: {
color: 'transparent'
}
},
vAxis: {
minValue: 0,
maxValue: 50000,
baselineColor: '#6ad4cd',
gridlines: {
color: '#6ad4cd',
count: 4
},
textStyle: {
fontSize: 11
}
},
legend: {
position: 'bottom',
textStyle: {
fontSize: 12
}
},
animation: {
duration: 1200,
easing: 'out',
startup: true
}
};
var lineChart = new google.visualization.LineChart(document.getElementById('line-chart'));
lineChart.draw(lineData, lineOptions);
// BEGIN PIE CHART
// pie chart data
var pieData = google.visualization.arrayToDataTable([
['Country', 'Page Hits'],
['USA', 7242],
['Canada', 4563],
['Mexico', 1345],
['Sweden', 946],
['Germany', 2150]
]);
// pie chart options
var pieOptions = {
backgroundColor: 'transparent',
pieHole: 0.4,
colors: [ "#339891",
"#ff8282",
"#6ad4cd"
],
pieSliceText: 'value',
tooltip: {
text: 'percentage'
},
fontName: 'Open Sans',
chartArea: {
width: '100%',
height: '94%'
},
legend: {
textStyle: {
fontSize: 13
}
}
};
// draw pie chart
var pieChart = new google.visualization.PieChart(document.getElementById('pie-chart'));
pieChart.draw(pieData, pieOptions);
}
<main>
<h2>Google Charts experiment</h2>
<h5>Daily Page Hits</h5>
<div id="bar-chart"></div>
<h5>Traffic Over Time</h5>
<div id="line-chart"></div>
<h5>Page Hits per Country</h5>
<div id="pie-chart"></div>
</main>
Google Charts experiment
------------------------
Playing with Google Charts and styling
A [Pen](https://codepen.io/rramona2/pen/KQxavX) by [ryan ramona](https://codepen.io/rramona2) on [CodePen](https://codepen.io).
[License](https://codepen.io/rramona2/pen/KQxavX/license).
以上是关于Angular Google Charts教程_编程入门自学教程_菜鸟教程-免费教程分享的主要内容,如果未能解决你的问题,请参考以下文章
如何在Angular中使用自定义比例绘制ng2-charts水平条形图?
使用 ng2-charts 和 Nathan Walker Angular2 NativeScript
markdown Google Charts实验
Google Charts:在相同的“X”值上绘制多个“Y”值
Google Charts列着色?
Google Charts interpolateNulls无效