score:3
You can control what you are asking for with a combination of tickInterval and min on the yaxis as demonstrated in this jsfiddle mock up.
EDIT
In your code while reading in the XML you will have to keep track of what the lowest value is and also the highest value on the sales side. Then decide how you want to display those values if they meet a certain value. After that use if statements to set the values. Here is a couple of examples.
Low less than -50 and greater -90
With High less than 400
Primary Axis: min: -2, tickInterval: 1,
Secondary Axis: min: -100, tickInterval: 50
Low less than -50 and greater -90
With High greater than 400
Primary Axis: min: -1, tickInterval: 1,
Secondary Axis: min: min: -100, tickInterval: 100,
To figure out what the min on the Primary Axis should be you simply divide the min on the Secondary Axis by its tickInterval. Then the tickInterval for the Primary Axis would always be 1.
score:0
You can also calculate second axis tick positions based on the max series value related to this axis and the first axis ticks positions to get the same amount of ticks and 0 line shared.
Using axis.update()
method update tick positions in the second axis using property tickPositions
.
Example with a load event. Notice, that when you add points dynamically you have to make those calculations and update tick positions each time your first axis ticks will change:
chart: {
type: 'column',
events: {
load: function() {
var chart = this,
yAxis = this.yAxis,
max = yAxis[1].dataMax,
positiveTicksAmount = 0,
negativeTicksAmount = 0,
tickPositions = [],
tickInterval,
min,
i;
yAxis[0].tickPositions.forEach(function(tick) {
if (tick > 0) {
positiveTicksAmount++;
} else if (tick < 0) {
negativeTicksAmount++;
}
});
tickInterval = max / positiveTicksAmount;
for (i = negativeTicksAmount; i > 0; i--) {
tickPositions.push(-tickInterval * i);
}
for (i = 0; i <= positiveTicksAmount; i++) {
tickPositions.push(
tickInterval * i
);
}
yAxis[1].update({
tickPositions: tickPositions
});
}
}
},
Jsfiddle examples:
https://jsfiddle.net/wchmiel/84q0sxrt/
http://jsfiddle.net/wchmiel/nuj7fagh/
Api reference:
https://api.highcharts.com/class-reference/Highcharts.Axis#update
https://api.highcharts.com/highcharts/yAxis.tickPositions
Source: stackoverflow.com
Related Query
- Highcharts - Issue with negative values when displaying multiple axes
- Highcharts cloud issue with data source when duplicating chart
- Highcharts issue with multiple X axes
- Highcharts - Keep Zero Centered on Y-Axis with Negative Values
- Highcharts - Column With Negative Values - Column Color
- Highcharts not displaying series data for graph with multiple Y-axes
- Highcharts - Area Chart - Stacking with series containing negative and positive values
- Highcharts column + line combination chart with multiple series. Issue aligning line over the column
- when printing page with highcharts using javascript this.print() width values in css in @media print seem to be ignored
- Highcharts multiple column chart with drilldown, correct formatting of drilldown axes
- Spiderweb Highcharts with multiple scales on multiple axes
- Highcharts synchronized charts with multiple axes datasets
- Highcharts redundant time data with multiple axes
- Highcharts with angularjs: smooth transition of bars when updating values
- Highcharts grouped bar charts with multiple axes
- Strange behavior with highcharts when using "column" type and multiple datetime series
- Highcharts - Cannot set x-axes categories in column charts with negative values
- Highcharts - yAxis dissapears, when zooming in to area with unknown values
- Highcharts timeline chart with multiple axes
- Column chart with negative values and categories on xAxis in HighCharts
- Have an issue with JavaScript, AJAX code displaying data
- Highcharts - Pie chart with negative values
- Graph issue when y-axis has only '0' as values in highcharts
- Highcharts multiple series combined with linkedTo hover issue
- resizing and positioning issue with gridster and multiple highcharts
- Highcharts click events not firing when displaying multiple line series
- HighCharts: How to draw a straight line in multiple axes like plotLines with fixed X-axis with different values
- Highcharts issue when dealing with 3D pie and large labels
- Highcharts issue when dealing with 3D pie and large labels
- highcharts gauge use with negative values
More Query from same tag
- Highcharts: Can sunburst chart show percentage share to depict part-to-whole relationship like pie charts?
- Highcharts: useHTML for labels creates empty label div every time Axis.update() is called
- Highstock - irregular time interval
- Getting Error Property 'nodeFormatter' does not exist on type 'SeriesOrganizationDataLabelsOptionsObject[]'
- Highcharts: Change needle color of Gauge Chart on Hover
- Highcharts Datetime Issue
- Access another series row's data on Highchart dataLabels
- Highcharts Synchronized charts display tooltip
- Rails and highcharts (data to highcharts)
- adding points to series using Highchart using c#
- Create a floating bar in HighCharts cloud
- Highcharts- how to set yAxis to the closest or exact value in the series data
- Strange behavior of Highchart tool tip
- HighCharts pointPlacement option not working in a single column chart
- Highcharts: how to set legend label name after chart created?
- Polymer dom-repeat not reflecting changes in array
- How to keep an empty slice area in highcharts after clicking on legendItem
- highcharts-ng show loading Image when loading
- (Highcharts) button inside tooltip can't trigger
- Get Key names and Values names from JSON and use in Highcharts
- Highcharts - export current state of a chart
- how to add tooltip on hover over the stacked Labels in highcarts
- How to import highchart-more into angular-cli 6 project
- How can I render a highcharts solidgauge with Django?
- animate addPlotBand Highcharts
- Highcharts: Add multiple colors to area line chart
- Loading json data to highcharts with multiple series
- How to add markers to a grouped bar plot in Highcharts?
- Draw custom bars in a Highcharts bar chart
- Highcharts treemap top and left borders missing