我目前有一个高图堆积柱形图,如下所示:
我有太多的数据要放在那个图表中,它看起来很丑陋而且不适合宽度:
请注意,我在两个屏幕截图中的每列中都有4种颜色
所以我想使用一个高价图表,用户可以放大和缩小数据,例如:https://www.highcharts.com/stock/demo/column
但是,有没有办法可以在保持堆叠的同时使用它?
这里的a fiddle包含我的堆积图表的小样本数据,这里是代码:
// Create the chart
Highcharts.chart('container',
{
"chart": {
"type": "column"
},
"title": {
"text": ""
},
"xAxis": {
"categories": [
"Start Term 1",
"Start Term 2",
"29-Sep",
"Start Term 3",
"03-Oct",
"05-Oct",
"Start Term 4",
"12-Oct",
"20-Oct",
"23-Oct",
"30-Oct",
"17-Nov",
"21-Nov"
],
"labels": {
"style": {
"font-size": "12px"
},
"useHTML": true
}
},
"yAxis": {
"title": {
"text": "Time (hh:mm)"
},
"tickInterval": 600,
"labels": {},
"gridLineWidth": 0,
"plotLines": [
{
"value": 0,
"width": 1,
"color": "#000",
"zIndex": 4
}
],
"tickmarkPlacement": "on"
},
"plotOptions": {
"column": {
"stacking": "normal",
"events": {}
}
},
"credits": {
"enabled": false
},
"tooltip": {
"shared": true,
"crosshairs": true
},
"legend": {
"align": "right",
"verticalAlign": "top",
"itemStyle": {
"display": "none"
},
"title": {
"text": "Click a colour"
}
},
"series": [
{
"name": "On Task Teacher Recommended",
"data": [
null,
null,
10688,
null,
4624,
4330,
null,
5220,
169,
5220,
4330,
9144,
4345
],
"color": "#86E067",
"events": {},
"point": {
"events": false
},
"customEvents": {
"series": {},
"point": {}
}
},
{
"name": "On Task Student Discovered",
"data": [
null,
null,
10373,
null,
5384,
5301,
null,
5521,
1002,
5599,
5387,
15535,
5373
],
"color": "#5CB5E5",
"events": {},
"point": {
"events": false
},
"customEvents": {
"series": {},
"point": {}
}
},
{
"name": "Uncategorised",
"data": [
null,
null,
341,
null,
226,
226,
null,
226,
425,
2240,
1281,
3727,
1334
],
"color": "#F98157",
"events": {},
"point": {
"events": false
},
"customEvents": {
"series": {},
"point": {}
}
},
{
"name": "Off Task",
"data": [
null,
null,
-18937,
null,
-7056,
-7034,
null,
-7163,
-1271,
-7208,
-7091,
-21658,
-7050
],
"color": "#E3454D",
"events": {},
"point": {
"events": false
},
"customEvents": {
"series": {},
"point": {}
}
}
]
}
);
答案 0 :(得分:0)
您可以使用scrollbars-for-any-axis在highstock等highboard中添加滚动。你必须使用highstock js而不是highcharts js。
您必须使用max
属性设置要在x轴上看到的列数。
// Create the chart
Highcharts.chart('container', {
"chart": {
"type": "column"
},
"title": {
"text": ""
},
"xAxis": {
"categories": [
"Start Term 1",
"Start Term 2",
"29-Sep",
"Start Term 3",
"03-Oct",
"05-Oct",
"Start Term 4",
"12-Oct",
"20-Oct",
"23-Oct",
"30-Oct",
"17-Nov",
"21-Nov"
],
"labels": {
"style": {
"font-size": "12px"
},
"useHTML": true
},
min: 0,
max: 4, //this is value to be changed based on column number
scrollbar: {
enabled: true
},
},
"yAxis": {
"title": {
"text": "Time (hh:mm)"
},
"tickInterval": 600,
"labels": {},
"gridLineWidth": 0,
"plotLines": [{
"value": 0,
"width": 1,
"color": "#000",
"zIndex": 4
}],
"tickmarkPlacement": "on",
},
"plotOptions": {
"column": {
"stacking": "normal",
"events": {}
}
},
"credits": {
"enabled": false
},
"tooltip": {
"shared": true,
"crosshairs": true
},
"legend": {
"align": "right",
"verticalAlign": "top",
"itemStyle": {
"display": "none"
},
"title": {
"text": "Click a colour"
}
},
"series": [{
"name": "On Task Teacher Recommended",
"data": [
null,
null,
10688,
null,
4624,
4330,
null,
5220,
169,
5220,
4330,
9144,
4345
],
"color": "#86E067",
"events": {},
"point": {
"events": false
},
"customEvents": {
"series": {},
"point": {}
}
}, {
"name": "On Task Student Discovered",
"data": [
null,
null,
10373,
null,
5384,
5301,
null,
5521,
1002,
5599,
5387,
15535,
5373
],
"color": "#5CB5E5",
"events": {},
"point": {
"events": false
},
"customEvents": {
"series": {},
"point": {}
}
}, {
"name": "Uncategorised",
"data": [
null,
null,
341,
null,
226,
226,
null,
226,
425,
2240,
1281,
3727,
1334
],
"color": "#F98157",
"events": {},
"point": {
"events": false
},
"customEvents": {
"series": {},
"point": {}
}
}, {
"name": "Off Task",
"data": [
null,
null, -18937,
null, -7056, -7034,
null, -7163, -1271, -7208, -7091, -21658, -7050
],
"color": "#E3454D",
"events": {},
"point": {
"events": false
},
"customEvents": {
"series": {},
"point": {}
}
}]
});
<!--<script src="https://code.highcharts.com/highcharts.js"></script>-->
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="https://code.highcharts.com/modules/drilldown.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
Fiddle演示
OR
您可以使用chart.zoomType缩放图表。
// Create the chart
Highcharts.chart('container',
{
"chart": {
"type": "column",
zoomType:'x' //only x axis zoom
},
"title": {
"text": ""
},
"xAxis": {
"categories": [
"Start Term 1",
"Start Term 2",
"29-Sep",
"Start Term 3",
"03-Oct",
"05-Oct",
"Start Term 4",
"12-Oct",
"20-Oct",
"23-Oct",
"30-Oct",
"17-Nov",
"21-Nov"
],
"labels": {
"style": {
"font-size": "12px"
},
"useHTML": true
}
},
"yAxis": {
"title": {
"text": "Time (hh:mm)"
},
"tickInterval": 600,
"labels": {},
"gridLineWidth": 0,
"plotLines": [
{
"value": 0,
"width": 1,
"color": "#000",
"zIndex": 4
}
],
"tickmarkPlacement": "on"
},
"plotOptions": {
"column": {
"stacking": "normal",
"events": {}
}
},
"credits": {
"enabled": false
},
"tooltip": {
"shared": true,
"crosshairs": true
},
"legend": {
"align": "right",
"verticalAlign": "top",
"itemStyle": {
"display": "none"
},
"title": {
"text": "Click a colour"
}
},
"series": [
{
"name": "On Task Teacher Recommended",
"data": [
null,
null,
10688,
null,
4624,
4330,
null,
5220,
169,
5220,
4330,
9144,
4345
],
"color": "#86E067",
"events": {},
"point": {
"events": false
},
"customEvents": {
"series": {},
"point": {}
}
},
{
"name": "On Task Student Discovered",
"data": [
null,
null,
10373,
null,
5384,
5301,
null,
5521,
1002,
5599,
5387,
15535,
5373
],
"color": "#5CB5E5",
"events": {},
"point": {
"events": false
},
"customEvents": {
"series": {},
"point": {}
}
},
{
"name": "Uncategorised",
"data": [
null,
null,
341,
null,
226,
226,
null,
226,
425,
2240,
1281,
3727,
1334
],
"color": "#F98157",
"events": {},
"point": {
"events": false
},
"customEvents": {
"series": {},
"point": {}
}
},
{
"name": "Off Task",
"data": [
null,
null,
-18937,
null,
-7056,
-7034,
null,
-7163,
-1271,
-7208,
-7091,
-21658,
-7050
],
"color": "#E3454D",
"events": {},
"point": {
"events": false
},
"customEvents": {
"series": {},
"point": {}
}
}
]
}
);
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="https://code.highcharts.com/modules/drilldown.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
Fiddle演示