score:7
Edit: Actually setting the item width did work, probably a better solution.
Setting the itemWidth doesn't work for me, however you can do something like this:
labelFormatter: function() {
var words = this.name.split(/[\s]+/);
var numWordsPerLine = 4;
var str = [];
for (var word in words) {
if (word > 0 && word % numWordsPerLine == 0)
str.push('<br>');
str.push(words[word]);
}
return str.join(' ');
}
See http://jsfiddle.net/ArmRM/13520/ for an example.
score:0
You can use
labelFormatter: function() {
return this.name; // insert your formatter function here
}
in your label and you can add html tags in the formatter. In this case you can add <br>
tags to manually break lines.
Please see: http://www.highcharts.com/ref/#legend--labelFormatter
score:0
For anyone else using the useHTML
option, you'll run into an issue with the default textOverflow: "ellipsis"
setting messing with your wrapping.
As teran noted above, setting textOverflow: null
inside itemStyle
will instantly fix your wrapping when useHTML
is enabled and you're trying to wrap custom HTML you've written inside legendFormatter()
.
Without this, the default truncation doesn't apply to your HTML (e.g. not a string) and just acts like you have overflow: hidden
set.
score:1
Setting the itemStyle on the legend has a bug. Long labels with no spaces still don't wrap.
Here is a label renderer function that wraps to a specific number of characters (I hard coded 20 into it) and will force a break in words that are longer than that:
function hcLabelRender(){
var s = this.name;
var r = "";
var lastAppended = 0;
var lastSpace = -1;
for (var i = 0; i < s.length; i++) {
if (s.charAt(i) == ' ') lastSpace = i;
if (i - lastAppended > 20) {
if (lastSpace == -1) lastSpace = i;
r += s.substring(lastAppended, lastSpace);
lastAppended = lastSpace;
lastSpace = -1;
r += "<br>";
}
}
r += s.substring(lastAppended, s.length);
return r;
}
It can be used like:
legend:{
labelFormatter: hcLabelRender
}
score:1
If you want all items on their own lines, you can use
legend: {
layout: "vertical"
}
score:3
Way to wrap long legend name
legend: {
enabled: true,
width:555,
itemWidth:500,
itemStyle: {
width:500
}
}
score:8
as a note, in 2017 you can use textOverflow
option
legend.itemStyle
CSS styles for each legend item. Only a subset of CSS is supported, notably those options related to text. The default
textOverflow
property makes long texts truncate. Set it tonull
to wrap text instead.
score:41
You can use:
legend: {
itemStyle: {
width: 90 // or whatever
},
}
And Highcharts will wrap the items for you.
Source: stackoverflow.com
Related Query
- How to wrap legend items in highcharts?
- Highcharts - How to programmatically toggle legend items and determine which items are selected
- How to suppress items with NULL value from HighCharts legend
- Highcharts Pie Chart: How to ignore disabled legend items
- How to modify highcharts legend item click event?
- Highcharts - How to display legend symbol inside the tooltip
- Display legend items in two columns highcharts
- Turn long list of items in Highcharts legend into dropdown
- How to Check and Uncheck all the Legend elements in HighCharts Linechart?
- How get data name in Highcharts pie chart legend instead of "Slice" using array of values?
- How do I remove the color swatch from my HighCharts legend without affecting the column?
- How to align highcharts legend to bottom right?
- How can i force Highcharts to use same symbols in Legend and Series?
- Highcharts putting extra space among legend items
- Highcharts - How do I get dashed lines in legend
- highcharts legend items align to the left when width is set
- How to center highcharts pie chart and legend on a page?
- How to trigger a legend click in HighCharts with jQuery?
- How to color series legend in highcharts when colorbypoint is set to true
- How do i add mouse wheel code in Angular2 highcharts in typescript
- how to display 2 same highcharts without duplicate the code
- How to edit tooltip in Highcharts C# code
- Highcharts server side image generation, how to set up legend labelFormatter in callback argument
- Jquery Highcharts Legend items sorting
- How to make legend color show up in Highcharts for a line graph under certain conditions?
- How to keep the highcharts legend "on" while hiding the series
- how to use highcharts tooltip formatter in python code
- highcharts - how do I do custom labels on heatmap legend
- How to reset items in legend area in Highcharts?
- How to show the legend in HighCharts
More Query from same tag
- Different approach to generate PDF of a HTML page which contains 10 highcharts using mPDF in PHP
- Customize Stacked column chart in highChart
- Highstock scrollbar not covering the whole length in multiple series
- Gradient background bars in Highchart bar chart
- Drilldown in Map with Vue.js
- highcharts. How to determine the coordinates of the point where the CLICK was made?
- Customizing the series data in pie charts with a dynamic json series (HighCharts)
- Set Opacity Pie Chart Highcharts
- How to apply color gradient in progress bar in high chart with stylemode in Angular
- Highchart line chart circle around datalabel
- Highcharts Pie Chart - slice color dependent of category
- Disable hover on HighCharts
- Generate a line chart over column chart using highcharts
- Highcharts: duplicate datalabel text on export
- Heroku and HighCharts Rails Gem -
- Zoom option if highcharts is working randomly
- How do I change a specific bar color in Highcharts Bar Chart?
- Higcharts: how to remove the styles of the tooltip container?
- How to position heatmap legend title in different position?
- How to put date into drilldown chart title based on drilled point x value (datetime)..?
- Custom YTD Option in HighStock Range Selector
- Alternating x-Axis plotbands with highstock
- Series Data in HighChart
- How to increase series data label in highcharts packed bubble
- how to set border radius for stacked bar in highcharts
- Motion in drilldown bubble chart Highcharts
- Highcharts Activity Gauge - how to get different behaviors while hover over
- Highcharts multiple stacked columns
- Easy way to gather all the common properties of a chart, to not write them all the time?
- Issue with Scroll bar in Hicharts/Histock chart