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>
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>