score:3
it can be done using this approach:
- create a function which sort columns:
- loop through points and group them by category (apples, oranges etc)
- loop through each group of points and sort the group by y value
- loop through points in each group and set a newly calculated y position using
svgelement.attr
method (point.graphic is an svgelement instance). do the same forpoint.datalabel
and set a new position topoint.tooltippos
array (otherwise tooltip will be placed wrongly).
function sortcolumns() {
var chart = this,
pointsbycat = {},
zeropixels,
bottomypositive,
bottomynegative,
shapeargs;
chart.series.foreach(function(serie) {
serie.points.foreach(function(point, index) {
if (pointsbycat[point.category] === undefined) {
pointsbycat[point.category] = [];
}
pointsbycat[point.category].push(point);
});
});
highcharts.objecteach(pointsbycat, function(points, key) {
zeropixels = chart.yaxis[0].topixels(0) - chart.plottop;
bottomypositive = bottomynegative = zeropixels;
points.sort(function(a, b) {
return b.y - a.y;
});
points.foreach(function(point) {
if (point.series.visible) {
if (point.shapeargs.y < zeropixels) {
// positive values
point.graphic.attr({
y: bottomypositive - point.shapeargs.height
});
point.datalabel.attr({
y: bottomypositive - point.shapeargs.height / 2 - point.datalabel.height / 2
});
point.tooltippos[1] = bottomypositive - point.shapeargs.height;
bottomypositive = bottomypositive - point.shapeargs.height;
} else {
// negative values
point.graphic.attr({
y: bottomynegative
});
point.datalabel.attr({
y: bottomynegative + point.shapeargs.height / 2 - point.datalabel.height / 2
});
point.tooltippos[1] = bottomynegative;
bottomynegative = bottomynegative + point.shapeargs.height;
}
}
});
});
}
2) set above function as a callback to chart.events.load
and chart.events.redraw
events:
chart: {
type: 'column',
events: {
load: sortcolumns,
redraw: sortcolumns
}
}
demo:
api reference:
Source: stackoverflow.com
Related Query
- Highcharts - stacked column - order series index dynamically for each category
- Highcharts stacked column how to use different label on each category
- Show special symbol for each series in category in highcharts
- Highcharts datalabel for each stacked column
- How to reference yData from another series in each category of a highcharts column chart
- HighCharts adding a multi-select dropdown for each column of a series
- Add a line on each bar for stacked and grouped column in HighCharts
- How to add different series data for each categories in Stacked Column chart in Highcharts?
- Highcharts - get bottom position for each stacked category
- Highcharts - Add a tooltip suffix value dynamically for each series
- In highCharts so much space left for each category when using index with data
- Highcharts Stacked column drill down not working?> How to set drill down series for my scenario?
- How do you change the colour of each category within a highcharts column chart?
- set different colors for each column in highcharts
- Changing data dynamically for a series in Highcharts
- Highcharts - specifying order of stacked time series
- highcharts - precision for stacked column chart data labels
- Make stack label disabled for a column in stacked column graph in Highcharts
- Setting Highcharts Series and Category data dynamically
- How to show Legends for all the series data in stacked column chart Highcharts?
- Legend for each point in column chart in highcharts
- Set different width for each column in highcharts
- Highcharts - Stacked column data series
- Highcharts Polar Chart - Specify Data Series & Tooltips for each Axis
- How to add labels for highcharts activity gauge for each series
- Creating a drilldown chart with Highcharts that contain double(multiple) columns for each column (see example for better explanation)
- Add new series to the top of a highcharts stacked column chart
- Highcharts - series order on stacked charts
- Highcharts columns with index on each column bottom
- Highcharts data series label. for each data point
More Query from same tag
- get values of date-input-boxes from rangeSelector
- Highcharts dynamic-update example - adding 1 new value every second - without historic data
- Calling Typescript function from Highcharts load event
- how to animate highcharts marker symbol on chart load
- Highcharts pie graph with two rings filtering
- Entire Highchart API calling from JSON file
- Highcharts - Redraw empty chart
- Highcharts - zoom xAxis and pan along axis
- How do I make npm pack "highcharts-export-server" wait for it to finish processing
- Remove step line points
- How to customize the polar chart in this way?
- Datalabels are not shown in 3D Highcharts bar/column
- Highmap: trigger hover + show tooltip of country on hover bubble data
- Cannot find type definition file for 'highcharts'
- How to update current view in Highstock / Highcharts based on new Plotlines?
- Highcharts datalabel 'callout' shape not working for donut chart
- PHP & Javascript Date Issue
- How to get multiple series data in tooltip highcharts?
- Reading MySQL data into highstocks
- Highcharts bubble chart dataLabels overlapping despite z-index
- How to create 2 separated xAxis chart
- Dymanically Update Data in Highchart: Load Event is not Working
- HighCharts-XRange Series: how to restrict data labels width to stay within corresponding data point width
- Highcharts piechart is not drawing slices from JSON object
- Using the accessibility.js module with highcharter
- How to set Highchart datetime format to minute?
- Highstock export csv based on data grouping
- Highcharts 3.0 Bubble Chart -- Controlling bubble sizes
- Highcharts - Tooltip and series name are out of their boxes in chrome
- How to deal in Highcharts with special characters from CSV file?