http://jsfiddle.net/highcharts/jrXQe/
$(function () {
/**
* Experimental Highcharts plugin to implement chart.alignThreshold option.
* Author: Torstein Hønsi
* Last revision: 2013-12-02
*/
(function (H) {
var each = H.each;
H.wrap(H.Chart.prototype, 'adjustTickAmounts', function (proceed) {
var ticksBelowThreshold = 0,
ticksAboveThreshold = 0;
if (this.options.chart.alignThresholds) {
each(this.yAxis, function (axis) {
var threshold = axis.series[0] && axis.series[0].options.threshold || 0,
index = axis.tickPositions && axis.tickPositions.indexOf(threshold);
if (index !== undefined && index !== -1) {
axis.ticksBelowThreshold = index;
axis.ticksAboveThreshold = axis.tickPositions.length - index;
ticksBelowThreshold = Math.max(ticksBelowThreshold, index);
ticksAboveThreshold = Math.max(ticksAboveThreshold, axis.ticksAboveThreshold);
}
});
each(this.yAxis, function (axis) {
var tickPositions = axis.tickPositions;
if (tickPositions) {
if (axis.ticksAboveThreshold < ticksAboveThreshold) {
while (axis.ticksAboveThreshold < ticksAboveThreshold) {
tickPositions.push(
tickPositions[tickPositions.length - 1] + axis.tickInterval
);
axis.ticksAboveThreshold++;
}
}
if (axis.ticksBelowThreshold < ticksBelowThreshold) {
while (axis.ticksBelowThreshold < ticksBelowThreshold) {
tickPositions.unshift(
tickPositions[0] - axis.tickInterval
);
axis.ticksBelowThreshold++;
}
}
//axis.transA *= (calculatedTickAmount - 1) / (tickAmount - 1);
axis.min = tickPositions[0];
axis.max = tickPositions[tickPositions.length - 1];
}
});
} else {
proceed.call(this);
}
})
}(Highcharts));
$('#container').highcharts({
chart: {
alignThresholds: true,
type: 'area'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: [{
title: {
text: 'Primary Axis'
},
gridLineWidth: 0
}, {
title: {
text: 'Secondary Axis'
},
opposite: true
}],
legend: {
layout: 'vertical',
backgroundColor: '#FFFFFF',
floating: true,
align: 'left',
x: 100,
verticalAlign: 'top',
y: 70
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y;
}
},
series: [{
data: [29.9, -71.5, -106.4, -129.2, -144.0, -176.0, -135.6, -148.5, -216.4, -194.1, -95.6, -54.4]
}, {
data: [129.9, 271.5, 306.4, -29.2, 544.0, 376.0, 435.6, 348.5, 216.4, 294.1, 35.6, 354.4],
yAxis: 1
}]
});
});
'프로그램언어 > 자바스크립트' 카테고리의 다른 글
iframe 안에 정의된 자바스크립트 변수를 iframe 밖에서 jQuery 로 접근하는 방법, contentWindow (0) | 2013.09.27 |
---|---|
jquery $(document).ready, $(window).load 이벤트차이 (0) | 2013.08.30 |