13. 数据积累(柱体的叠加)


示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>柱状图 - 数据积累(柱体的叠加)</title>
</head>

<body>
<div id='A13' style='position:relative; width: 600px; height:300px; '></div>

<script src='../dist/column.js'></script>
<script>

createChart('A13');

function createChart(divID)
{
//1. 生成图表对象
let chart = new T.column.Chart(divID);

//2. 停止图表绘制
chart.stop() ;

//3. 准备数据
let data1 = [];
let data2 = [];
let data3 = [];
for (let i = 0; i < 9; i++) {
data1.push(Number( (Math.random() * 2).toFixed(2)) );
data2.push(Number( -Math.random().toFixed(2)));
data3.push(Number( -(Math.random() * 5).toFixed(2)));
}

let series1 = new T.column.Series();
series1.name = '系列1';
series1.stackName = ''; //具有相同stackName的系列数据将被累加
series1.data = data1;

let series2 = new T.column.Series();
series2.name = '系列2';
series2.stackName = 'AA';
series2.data = data2;

let series3 = new T.column.Series();
series3.name = '系列3';
series3.stackName = 'AA';
series3.data = data3;

//4. 设置图表信息
let chartInfo_In = chart.chartInfo_In ;
chartInfo_In.title = '柱状图';
chartInfo_In.series = [series1,series2,series3];

//5. 设置类目轴数据
let cAxisInfo_In = chart.cAxisInfo_In ;
cAxisInfo_In.categorys = ['分类1','分类2','分类3','分类4','分类5','分类6','分类7','分类8','分类9'];

//6. 设置数值轴数据
//无

//7. 开始图表绘制
chart.start();
}

</script>
</body>
</html>