Hi I a'm trying to position caption on 'top' and control margin between caption and plotArea using caption.margin property. Works perfectly for 'bottom' aligned caption, but not 'top'. Please advise. Here is an example https://jsfiddle.net/sabira/e7kdz32v/11/:
Highcharts.chart('container', {
title: {
text: ''
},
xAxis: {
categories: ['Apples', 'Pears', 'Bananas', 'Oranges']
},
series: [{
data: [1, 4, 3, 5],
type: 'column',
name: 'Fruits'
}],
caption: {
verticalAlign: 'top',
margin: 100,
text: '<b>The caption renders in the top, and is part of the exported chart.</b>'
}
});
That works in the opposite way as a margin for title: http://jsfiddle.net/BlackLabel/4w3az2qd/. As a solution, instead of caption you can use title, subtitle or caption with padding-bottom style:
caption: {
verticalAlign: 'top',
useHTML: true,
style: {
'padding-bottom': '100px'
},
text: '<b>The caption renders in the top, and is part of the exported chart.</b>'
}
Live demo: https://jsfiddle.net/BlackLabel/j8gv1k9L/
API Refefence: https://api.highcharts.com/highcharts/caption.useHTML
Related
Can someone help me to wrap y-axis title please (I am using styled mode)?
Here's an example: https://jsfiddle.net/sabira/6s3wa0m7/
Highcharts.chart('container', {
chart: {
styledMode: true,
type: 'column'
},
title: {
text: 'test'
},
yAxis: [{
className: 'highcharts-color-0',
title: {
text: 'very long title text here very long title text here very long title text here very long title text here '
}
}],
plotOptions: {
column: {
borderRadius: 5
}
},
series: [{
data: [1, 3, 2, 4]
}, {
data: [324, 124, 547, 221],
}]
});
Use the below CSS styles:
.highcharts-axis-title {
width: 200px;
white-space: normal !important;
}
Live demo: https://jsfiddle.net/BlackLabel/gqud6c0L/
I want to make a chart like this in highchart. How can I add the yellow colored box in my chart
It can be made by adding additional x-axes (in a bar chart x-axes are vertical ones) and setting them as opposite and linked to the main axis. Check the code and demo posted below and let me know if something is unclear to you.
Code:
const defaultLabelOptions = {
opposite: true,
linkedTo: 0,
lineWidth: 0,
tickWidth: 0
};
const defaultAxisTitleOptions = {
align: 'high',
rotation: 0,
margin: 0,
textAlign: 'center',
style: {
'text-decoration': 'underline',
'font-weight': 'bold'
}
};
// ...
xAxis: [{
categories: ['Africa', 'America', 'Asia', 'Europe', 'Oceania'],
title: {
text: null
}
}, {
...defaultLabelOptions,
offset: 50,
labels: {
align: 'right',
formatter: function() {
return labels.le[this.value];
}
},
title: {
text: 'LE',
...defaultAxisTitleOptions
}
}, {
...defaultLabelOptions,
offset: 110,
labels: {
align: 'right',
formatter: function() {
return labels.tgt[this.value];
}
},
title: {
text: 'TGT',
...defaultAxisTitleOptions
}
}]
Demo:
https://jsfiddle.net/BlackLabel/68hdutxv/
API reference:
https://api.highcharts.com/highcharts/yAxis.opposite
https://api.highcharts.com/highcharts/yAxis.linkedTo
If you want to have lines between the additional axes you can add them using Highcharts.SVGRenderer: https://api.highcharts.com/class-reference/Highcharts.SVGRenderer
When I use the highchart labels are not coming with the ellipsis style.
For that, I need to enter more texts to achieve that by default.
For example,
for the label text "Africa hi hello how are you. I am fine. thank you. what about you? how is going? Nothing special", it shows the ellipsis as "Africa hi hello how are yo.."
But if I remove "Nothing special" and having only the following sentence, "Africa hi hello how are you. I am fine. thank you. what about you? how is going?", then labels are wrapped instead of applying ellipsis.
I have tried the formatter, but the tooltip is not coming by default.
If I use, usehtml property the design gets collapsed.
Please see the following code.
Highcharts.chart('container', {
chart: {
type: 'bar'
},
title: {
text: 'Historic World Population by Region'
},
subtitle: {
text: 'Source: Wikipedia.org'
},
xAxis: {
categories: ['Africa hi hello how are you. I am fine. thank you. what about you? ho?', 'America', 'Asia', 'Europe', 'Oceania'],
title: {
text: null
},
labels:{
formatter: function () {
return this.value;
}, style: {
color: 'black',
overflow:'none'
}
}
},
yAxis: {
min: 0,
title: {
text: 'Population (millions)',
align: 'high'
},
labels: {
overflow: 'justify'
},
},
tooltip: {
valueSuffix: ' millions'
},
plotOptions: {
bar: {
stacking:'normal',
dataLabels: {
enabled: true
}
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -40,
y: 80,
floating: true,
borderWidth: 1,
backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
shadow: true
},
credits: {
enabled: false
},
series: [{
name: 'Year 1800',
data: [107, 31, 635, 203, 2]
}, {
name: 'Year 1900',
data: [133, 156, 947, 408, 6]
}, {
name: 'Year 2000',
data: [814, 841, 3714, 727, 31]
}, {
name: 'Year 2016',
data: [1216, 1001, 4436, 738, 40]
}]
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; max-width: 800px; height: 400px; margin: 0 auto"></div>
Notice that in the demo that you provided the look of the label depends on the size of the chart. Ellipsis is applied when the width is very small. Otherwise words of the label are wrapped.
Your example as live demo: http://jsfiddle.net/BlackLabel/c7f2oadg/
Use configuration similar to the below one if you want to be sure that ellipsis will always be applied to long labels:
style: {
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
width: 100,
}
width causes here that ellipsis will be used in all labels wider than 100 px.
Live demo: http://jsfiddle.net/BlackLabel/v213vwts/
API reference: https://api.highcharts.com/highcharts/xAxis.labels.style
How do I prevent labels from wrapping in Highcharts styled mode? A partial solution that I found is to use the useHTML flag and set white-space: nowrap; with css, but then the labels are rendered on top of the tooltip. If I set useHTML to false, then highcharts automatically adds line breaks. I've included a code snippet to illustrate the problem. Just run the snippet and hover your mouse over the bottom bar.
Highcharts.chart('container', {
chart: {
type: 'bar',
borderWidth: 1
},
title: {
text: 'No space reserved for X axis labels'
},
credits: {
enabled: false
},
legend: {
enabled: false
},
xAxis: {
categories: ['Product 1', 'Product 2', 'Yet another product with a long label'],
labels: {
rotation: 0,
align: 'left',
reserveSpace: false,
x: 2,
y: -5,
useHTML: true
},
tickWidth: 0
},
series: [{
data: [39.9, 71.5, 50.4],
dataLabels: {
enabled: true
}
}]
});
#import 'https://code.highcharts.com/css/highcharts.css';
.highcharts-axis-labels span {
white-space: nowrap!important;
}
<script src="https://code.highcharts.com/js/highcharts.js"></script>
<div id="container" style="height: 400px; width: 500px"></div>
To make it work with styled version of Highcharts, you can wrap addLabel function of Tick prototype. Take a look at the example below.
Example:
http://jsfiddle.net/vsy8abLb/
I am generating my x-axis and y-axis data dynamically and displaying highcharts, but the chart becomes messy when the x-axis range is high with small intervals.
How do I make highcharts to make normal horizontally scrollable graph?
Here is what I am using right now:
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
//CODE FOR HIGHCHARTS JS
function makeChart() {
$('#container').highcharts({
chart: {
type: 'line',
marginRight: 130,
marginBottom: 100
},
title: {
text: 'Banana',
x: -20 //center
},
subtitle: {
text: 'Source: banana.com',
x: -20
},
xAxis: {
categories: xlist
},
yAxis: {
title: {
text: 'No. of C'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: 'C'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: [{
name: $("#repoSelector option:selected").text(),
data: ylist
}]
});
}
Two ways to achieve a scroll bar.
Option 1
You will need to use highstock.js and instead of rendering a stock chart, you have to render a highchart.
Then enable the scroll bar
scrollbar: {
enabled: true
}
Check the API for scroll bar and related operations here.
Here I have fiddled an example.
Option 2
Try setting min & max attributes to the x-axis.
xAxis: {
categories: [...],
min: 0,
max:9
}
Displays 10 categories in x-axis at a stretch, adding a scroll for the rest of the categories.
find the fiddled example here.
To enable scrollbar in x-axis, try this
xAxis: {
categories: xlist,
min: 0,
max: 4,
scrollbar: {
enabled: true
},
},
Check the jfiddle here: https://jsfiddle.net/BhavyaAprajita/zja90wf2/1/
Also, make sure that you import the highstock library
src="https://code.highcharts.com/stock/highstock.js"
add this
const Highcharts = require('highcharts/highstock');
comment this if you have
// import Highcharts from 'highcharts';
change xAxis to like this
xAxis : {
categories: [],
min:0,
max:9,
scrollbar: {
enabled: true
}
}
Use
require('highcharts/highmaps') instead of require('highcharts') in imports<br>
#NgModule({<br>
...<br>
imports: [<br>
BrowserModule, <br>
ChartModule.forRoot( <br>
require('highcharts/highmaps')<br>
],<br>
})