score:1
i have managed to solve this thanks to support from highcharts themselves. the idea is to set the tick position on the load
event and use the labels.formatter
for formatting each individual label.
events: {
load() {
let labelgroup = document.queryselectorall('.highcharts-yaxis-labels');
// nodevalue is distance from top
let ticks = document.queryselectorall('.highcharts-yaxis-grid');
let tickpositions = array.from(ticks[0].childnodes).map(
function(node){
return +node.attributes.d.nodevalue.split(" ")[2];
}
);
let labelpositions = [];
for(let i =1 ;i<tickpositions.length;i++){
labelpositions.push((tickpositions[i] + tickpositions[i-1])/2);
}
labelgroup[0].childnodes[0].attributes.y.nodevalue = labelpositions[0] + parsefloat(labelgroup[0].childnodes[0].style["font-size"], 10) / 2;
labelgroup[0].childnodes[1].attributes.y.nodevalue = labelpositions[1] + parsefloat(labelgroup[0].childnodes[1].style["font-size"], 10) / 2;
labelgroup[0].childnodes[2].attributes.y.nodevalue = labelpositions[2] + parsefloat(labelgroup[0].childnodes[2].style["font-size"], 10) / 2;
labelgroup[0].childnodes[3].attributes.y.nodevalue = labelpositions[3] + parsefloat(labelgroup[0].childnodes[3].style["font-size"], 10) / 2;
labelgroup[0].childnodes[4].attributes.y.nodevalue = labelpositions[4] + parsefloat(labelgroup[0].childnodes[4].style["font-size"], 10) / 2;
}
}
and the labels are formatted as:
labels: {
formatter: function() {
var chart = this.chart,
axis = this.axis,
label;
if (!chart.yaxislabelindex) {
chart.yaxislabelindex = 0;
}
if (this.value !== -1) {
label = axis.categories[chart.yaxislabelindex];
chart.yaxislabelindex++;
if (chart.yaxislabelindex === groups.length) {
chart.yaxislabelindex = 0;
}
return label;
}
},
}
fiddle at https://jsfiddle.net/yvnp4su0/42/
score:1
to create such a chart you will have to add 12 yaxis (0-11) and set proper ticks and labels so that only a-d categories will be plotted. additionally, adjust plotoptions.pointpadding and plotoptions.grouppadding properties to set points width automatically (series.pointwidth should be undefined then).
yaxis options:
yaxis: [{
title: {
text: "factions"
},
categories: ["a", "b", "c", "d"],
tickpositions: [-1, 2, 5, 8, 11],
linewidth: 0,
labels: {
y: -20,
formatter: function() {
var chart = this.chart,
axis = this.axis,
label;
if (!chart.yaxislabelindex) {
chart.yaxislabelindex = 0;
}
if (this.value !== -1) {
label = axis.categories[chart.yaxislabelindex];
chart.yaxislabelindex++;
if (chart.yaxislabelindex === 4) {
chart.yaxislabelindex = 0;
}
return label;
}
},
},
reversed: true
}]
score:1
as i suggested in the comment above it is a better idea to use highcharts renderer and add custom labels than manipulate dom elements as you did in the previous answer, because it is a much cleaner solution.
disable default labels:
yaxis: [{
title: {
text: "factions",
margin: 35
},
categories: ["a", "b", "c", "d", "e"],
tickpositions: tickpositions,
linewidth: 0,
labels: {
enabled: false
},
reversed: true
}]
add custom labels in proper positions using renderer:
chart: {
type: 'xrange',
height: 500,
marginleft: 60,
events: {
load: function() {
this.customlabels = [];
},
render: function() {
var chart = this,
yaxis = chart.yaxis[0],
categories = yaxis.categories,
xoffset = 15,
yoffset = 20,
xpos = yaxis.left - xoffset,
tickpositions = yaxis.tickpositions,
text,
label,
ypos,
tick1y,
tick2y,
i;
for (i = 0; i < tickpositions.length - 1; i++) {
if (chart.customlabels[i]) {
chart.customlabels[i].destroy();
}
tick1y = yaxis.topixels(tickpositions[i]);
tick2y = yaxis.topixels(tickpositions[i + 1]);
ypos = (tick1y + tick2y) / 2 + yoffset;
text = categories[i];
label = chart.renderer.text(text, xpos, ypos)
.css({
color: '#ccc',
fontsize: '14px'
})
.add();
chart.customlabels[i] = label;
}
}
}
}
Source: stackoverflow.com
Related Query
- Timeline chart with highcharts using x-range with multiple stacks
- Highcharts timeline chart with multiple axes
- Highcharts : using same div to load a chart multiple times with different series data
- How to create a column range chart in Highcharts using range and navigator functions?
- Multiple Series Timeline with HighCharts
- creating a bar chart using Highcharts with React - getting an error that rendering div isn't found
- Highcharts Grouped Column Chart with Multiple Groups?
- Using Trellis Chart with Stacked Columns in Highcharts
- Highcharts problem with xAxis using multiple series
- Highcharts column + line combination chart with multiple series. Issue aligning line over the column
- Change chart type and redraw with multiple series in Highcharts
- Using wkhtmltopdf with highcharts shows blank chart
- Highcharts multiple column chart with drilldown, correct formatting of drilldown axes
- How to use Highcharts React to create chart with multiple lines for same XAxis?
- Drawing Bubble Chart by using npm highcharts with error #17
- Charts using Highcharts with multiple series from JSON
- Strange behavior with highcharts when using "column" type and multiple datetime series
- Multiple pie-charts in the same chart with HighCharts
- How can I make milestone lines with a GANTT chart using the highcharts library?
- Rendering more than one chart with Highcharts using Angular js Directives
- highcharts change chart type using dropdown for multiple series
- How to specify a range of data when using HighCharts with <table>?
- How can I get a chart only with legends using highcharts
- Highcharts display label for pie chart using html table as data source
- dynamic chart with Highcharts using json
- Basic Highcharts Multiple Series Chart Using JSON
- Using columnrange chart type in Highcharts with custom output?
- Highcharts drilldown to pie chart - Clicking on axis label with multiple series causes pie charts to overlap
- How can I prepare a Group Stacked Bar Chart in Highcharts using multiple and different types of data?
- How to have multiple highcharts with different series data in vuejs without repeating code
More Query from same tag
- Highchart is blank
- highcharts display in my render html page which i want to convert into PDF using wkhtmltopdf in rails
- Highcharts with datetime and also additional data (tooltip text)
- How to get the path element of hovered scatter point
- Highcharts PieChart Legend paging faulty
- Highcharts: Display last values from stacked chart in legend
- how to present json data on Highchart
- HTML table as data source for highstock charts using highcharts
- Highstock chart offsets dates for no reason
- How to hide/disable the legend box in Highcharts.js?
- Highcharts - toggle table properly upon drilldown item
- Highcharts: Shared tooltip for heatmap
- how to add dynamic series in highcharts
- keep fixed size of the bars in Highcharts
- Highcharts Gauge
- Multiple Axes on a Highcharts Heatmap
- How to offset HighCharts data?
- Highcharts multilevel categories
- Use a variable for Highcharts yAxis.Max
- Disable highchart legend if series name = 'SP'
- How can i hide all the Series in highcharts at a time
- Vuejs Component Communication
- How to give hyperlink in HTML 5 Chart in iReport
- Make highcharts display the tooltip of the previous point
- How to create a new Highstock chart with new Highchart and not jquery?
- Highchart GMT and one hour offset
- Javascript,Highcharts : Avoiding parallel function calls
- How to store highcharts compatible json array data in mongodb
- Javascript Highcharts Mapping multiple values without showing them all in the chart
- rCharts: Highcharts - how to flip coordinates for bar chart?