您的位置:首页 > 其它

Highcharts set the min height for (column-stacked-and-grouped) chart.

2012-11-26 16:41 513 查看

The mian way.

1.use axis.translate function to
convert value to pixel and backward

point
to pixel:


plot_y = chart.yAxis[0].translate(point_y)

pixel
to point, simply add "true" as second parameter:


point_y
= chart.yAxis[0].translate(plot_y, true)



2.update([Mixed options], [Boolean redraw], [Mixed animation])



Update the point with new values.

Parameters

options: Number|Array|Object

The point options. If options is a single number, the point will be given that number as the y value.If it is an array, it will be interpreted as x and y values respectively. If it is an object, advanced options as outlined underseries.data
are applied.

redraw: Boolean

Defaults to
true
. Whether to redraw the chart after the point is updated.If doing more operations on the chart, it is a good idea to set redraw to false and call
chart.redraw()
after.

animation: Mixed

Defaults to true. When true, the update will be animated with default animationoptions. The animation can also be a configuration object with properties
duration
and
easing
.


<!DOCTYPE HTML>
<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 type="text/javascript">
$(function () {
var chart;
//set minHeight.
var minHeight = 10;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'column',
events: {
load: function(event) {
var chart = this.series[0].chart;
var series = chart.series;

for(var i = 0; i < series.length; i++){
var serieData = series[i].data;
console.log('series----------------------------------'+i+'-------------------------------------->'+series[i].name);
for(var j = 0; j < serieData.length; j++){
var dragPoint = serieData[j];
console.log('series******'+ i +'serieData****************************************' + j);
if(dragPoint){
console.log('dragPoint.x----'+dragPoint.x);
console.log('dragPoint.y----'+dragPoint.y);
console.log('barX----'+dragPoint.barX);
console.log('plotY-----'+dragPoint.plotY);
console.log('yBottom-----'+dragPoint.yBottom);
console.log('chart.plotHeight----'+chart.plotHeight);
console.log('shapeArgs.height---'+dragPoint.shapeArgs.height);
console.log('shapeArgs.width---'+dragPoint.shapeArgs.width);
console.log('shapeArgs.x---'+dragPoint.shapeArgs.x);
console.log('shapeArgs.y---'+dragPoint.shapeArgs.y);
//var series = dragPoint.series;
var	newX = dragPoint.x;
var newY;
if(dragPoint.y != 0 && dragPoint.shapeArgs.height < minHeight){
newY = dragPoint.series.yAxis.translate(minHeight, true);
dragPoint.update([newX, newY], false);
}
}
}
}

chart.redraw();
}
}
},

title: {
text: 'Total fruit consumtion, grouped by gender'
},

xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
},

yAxis: {
allowDecimals: false,
min: 0,
title: {
text: 'Number of fruits'
}
},

tooltip: {
formatter: function() {
return '<b>'+ this.x +'</b><br/>'+
this.series.name +': '+ this.y +'<br/>'+
'Total: '+ this.point.stackTotal;
}
},

plotOptions: {
column: {
stacking: 'normal'
}
},

series: [{
name: 'John',
data: [5, 300, 400, 700, 20],
stack: 'male'
}, {
name: 'Joe',
data: [30, 40, 400, 200, 50],
stack: 'male'
}, {
name: 'Jane',
data: [20, 500, 60, 200, 100],
stack: 'female'
}, {
name: 'Janet',
data: [3, 0, 400, 400, 3],
stack: 'female'
}]
});
});

});
</script>
</head>
<body>
<script src="../../js/highcharts.js"></script>
<script src="../../js/modules/exporting.js"></script>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐