highcharts 柱狀圖 數據是從數據庫取出的,需求是我想用幾個複選框控制每根柱子的顯示和隱藏,怎麼實現?
2013-08-20 08:52piaomiaowc | 分類:JavaScript | 瀏覽1085次
最好是有隱藏的方法,從數據的控制可以解決,但是比較麻煩,我是把不要的柱子的數據清零,要呈現的時候再恢復數據的。太麻煩,柱子多的時候,要多好多代碼。求大俠指點
分享到:
2013-08-20 15:49 提問者採納
基本實現方法如下:
1、設置 plotOptions.column.showCheckbox 爲ture,目的是顯示checkbox
1
2
3
4
5
plotOptions: {
column:{
showCheckbox:true,
}
}
2、設置column的checkboxClick事件,設置該series顯示與隱藏
1
2
3
4
5
6
7
8
9
10
11
12
13
14
plotOptions: {
column:{
events :{
checkboxClick: function(event) {
if(event.checked==true) {
this.show();
}
else {
this.hide();
}
},
}
}
}
給你完整的代碼
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE HTML》<!-- highcharts 學習交流294191384-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script type="text/javascript">
var options = {
chart: {
renderTo: 'container',
type: 'column',
backgroundColor: {
linearGradient: [0, 0, 500, 500],
stops: [
[0, 'rgb(255, 255, 255)'],
[500, 'rgb(240, 240, 255)']
]
},
spacingBottom:30,
zoomType:'x'
},
title: {
text: 'sdsd',
y:30,
style :{
color:'red',
fontSize:'25px'
},
margin :20
},
credits:{
enabled:false
},
xAxis: {
title :{
text:'sdsd',
align:'middle'
},
margin: 100,
},
yAxis: [{
title: {
text: 'sdsd'
}
}],
plotOptions: {
column:{
dataLabels: {
enabled: true
},
animation:false,
lineWidth:3,
selected:true,
zIndex:10,
showCheckbox:true,
selected:true,
events :{
checkboxClick: function(event) {
if(event.checked==true) {
this.show();
}
else {
this.hide();
}
},
legendItemClick:function(event) {//return false 即可禁用LegendIteml
return false;
}
}
}
},
legend:{
floating :true,
align: 'left',
verticalAlign: 'bottom',
x:60,
y:15
},
series: [{
yAxis:0,
name:'sd',
}]
};
$(document).ready(function(){
options.xAxis.categories = [1,2,3,4,5,6];
options.series[0].data = [1,2,3,3,2,1];
var char = new Highcharts.Chart(options);
$("button").click(function(){
options.xAxis.categories = [1,2,3,4,5,6];
options.series[0].data = [10,2,5,2,9,1];
//options.series[0].pointStart = 2;
var series1 = {
yAxis:0,
name:'1111',
data:[2,9,1,10,2,5]
};
char = new Highcharts.Chart(options);
char.addSeries(series1);
});
});
</script>
</head>
<body>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
<button>change</button>
</body>
</html>
需求是我想用幾個複選框控制每根柱子的顯示和隱藏
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
Json字符串和highcharts數據圖表展現
Amiao999
2020-02-25 01:33:35
appframework(2.1) 小技巧(更新中)
Amiao999
2020-02-25 01:33:35
jqmobi如何隱藏頭部底部 Hide Footer Menu
Amiao999
2020-02-25 01:33:35
data-ignore="True"會導航到index.html頁面,並不會把index.html的內容加載到dom中
Amiao999
2020-02-25 01:33:35
webApp 開發技術要點總結(轉)
Amiao999
2020-02-25 01:33:35
Json字符串和highcharts數據圖表展現
Amiao999
2020-02-25 01:33:35
appframework(2.1) 小技巧(更新中)
Amiao999
2020-02-25 01:33:35
jqmobi如何隱藏頭部底部 Hide Footer Menu
Amiao999
2020-02-25 01:33:35
highcharts+json+ashx 圖表動態數據綁定
Amiao999
2020-02-25 01:33:35
解決辦法:Synchronous XMLHttpRequest on the main thread is deprecated because of its
Amiao999
2020-02-25 01:33:35
請求jquery.min.js的時候,log顯示瀏覽器還請求了jquery.min.map,該請求導致服務端報錯
Amiao999
2020-02-25 01:33:35
data-ignore="True"會導航到index.html頁面,並不會把index.html的內容加載到dom中
Amiao999
2020-02-25 01:33:35
得到數據庫中的數據,並在Highcharts控件中顯示
Amiao999
2020-02-25 01:33:35