/*
* Highcharts plugin for adding an axis after render time. Works with Highcharts >= 2.2.4.
* As of Highcharts 3.0, the contents of this plugin will be part of the Highcharts
* core.
* Author: Torstein Hønsi
* License: MIT License
* Last revision: 2013-03-08
*/
(function (Highcharts) {
var each = Highcharts.each,
UNDEFINED;
/**
* Utility function to remove last occurence of an item from an array
* @param {Array} arr
* @param {Mixed} item
*/
function erase(arr, item) {
var i = arr.length;
while (i--) {
if (arr[i] === item) {
arr.splice(i, 1);
break;
}
}
return i;
}
/**
* Add an axis to the chart
* @param {Object} options The axis option
* @param {Boolean} isX Whether it is an X axis or a value axis
*/
Highcharts.Chart.prototype.addAxis = function (options, isX) {
var chart = this,
key = isX ? 'xAxis' : 'yAxis',
axis = new Highcharts.Axis(this, Highcharts.merge(options, {
index: chart[key].length
}));
// Push the new axis options to the chart options
chart.options[key] = Highcharts.splat(chart.options[key] || {});
chart.options[key].push(options);
};
/**
* Remove an axis from the chart
*/
Highcharts.Axis.prototype.remove = function () {
if (this.series.length) {
console.error('Highcharts error: Cannot remove an axis that has connected series');
} else {
var chart = this.chart,
key = this.isXAxis ? 'xAxis' : 'yAxis';
// clean up chart options
var axisIndex = this.options.index;
chart.options[key].splice(axisIndex, 1);
erase(chart.axes, this);
var index = erase(chart[key], this);
// clean up following axis options...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.