Related
I want to display a data label on the last point of a series in a line chart and added this code:
dataLabels: {
enabled: true,
formatter: function() {
if (this.x == this.series.data[this.series.data.length - 1].x) {
return 'Test';
} else {
return null;
}
}
},
Unfortunately the data label is not dislayed. See fiddle
Your series contains 63 points, but only 23 of them have defined y property and are displayed. You need to filter the visible points and get the last of them, for example by:
dataLabels: {
enabled: true,
formatter: function() {
var visiblePoints = this.series.points.filter(p => typeof p.y === 'number');
if (this.x == visiblePoints[visiblePoints.length - 1].x) {
return 'Test';
} else {
return null;
}
}
}
Live demo: https://jsfiddle.net/BlackLabel/e50jspxu/
You can look this =>
working example
Highcharts.chart('container', {
chart: {
height: 800,
style: {
color: '#2e4964',
},
events: {
load() {
let chart = this;
chart.series.forEach(s => {
s.setState('inactive')
})
}
}
},
title: {
text: 'Corona',
align: 'left',
y: 20,
margin: 0,
style: {
color: '#292929',
fontWeight: '700',
fontWeight: '600',
fontSize: '22px',
fontFamily: 'Fira Sans,sans-serif'
}
},
subtitle: {
text: 'Verlauf der Pandemie in den Ländern',
align: 'left',
useHTML: true,
style: {
fontFamily: 'Poppins',
fontWeight: '400',
color: '#373737',
fontSize: "14px"
}
},
xAxis: [{
type: 'linear',
min: 1,
max: 40,
tickInterval: 5,
tickLength: 5,
labels: {
style: {
fontFamily: 'Poppins',
fontWeight: '400',
color: '#373737',
fontSize: "14px"
}
},
title: {
text: ''
}
}],
yAxis: [{
type: 'logarithmic',
max: 40000,
// minorTickInterval: 1,
min: 100,
title: {
text: null
},
labels: {
style: {
fontFamily: 'Poppins',
fontWeight: '400',
color: '#373737',
fontSize: "14px"
}
}
}],
exporting: {
buttons: {
contextButton: {
enabled: false
}
}
},
legend: {
enabled: true,
reversed: false,
title: {
text: 'Länder an- und abwählen:',
style: {
fontFamily: 'Poppins',
fontWeight: '600',
color: '#373737',
fontSize: "14px"
}
},
layout: 'horizontal',
align: 'left',
verticalAlign: 'top',
width: 300,
maxHeight: 200,
x: -8,
padding: 10,
floating: false,
borderWidth: 0,
shadow: false,
itemMarginTop: 1,
itemStyle: {
fontFamily: 'Poppins',
fontWeight: '400',
color: '#373737',
fontSize: "14px"
}
},
// tooltip: {
// shared: false,
// useHTML: true,
// headerFormat: '<span style="white-space:normal;font-size: 14px;font-weight: 400;min-width: 200px;color: black;font-family:Poppins,sans-serif">Tag {point.x}</span><br>',
// pointFormat: '<span style="color:{point.color};">● </span><span style="white-space:normal;font-size: 14px;font-weight: 400;min-width: 200px;color: black;font-family:Poppins,sans-serif;margin-top: 50px;">{series.name} : </span><span style="white-space:normal;font-size: 14px;font-weight: 800;min-width: 200px;color: black;font-family:Poppins,sans-serif">{point.y:,.0f}<br/></b></span>',
// },
tooltip: {
useHTML: true,
enabled: true,
outside: true,
formatter: function() {
return '<div style="white-space:normal;font-size: 14px;font-weight: 400;min-width: 120px;color: #373737;font-family:Poppins">' + 'Tag ' + this.x + '<br>' + this.series.name + ': <b>' + Highcharts.numberFormat(this.point.y, 0) + '</b>';
}
},
credits: {
href: '',
position: {
align: 'right',
y: -35,
},
text: 'Quellen: JHU CSSE, WHO CDC, NHC, Dingxiangyua',
style: {
cursor: 'arrow',
fontFamily: 'Poppins',
fontWeight: 'normal',
fontSize: "12px"
}
},
plotOptions: {
series: {
dataLabels: {
align: 'right',
enabled: true,
allowOverlap: true,
formatter: function() {
if (this.x == this.series.data[this.series.data.length - 1].x) {
return '<span style="color: #373737;font-weight: normal">' + Highcharts.dateFormat("%e. %B", this.x) + '</span>:<br>' + '<span style="color: #003f6e;font-weight: bold">' + Highcharts.numberFormat(this.y, 0) + '</span>';
} else {
return null;
}
},
style: {
textOutline: 0,
fontFamily: 'Poppins',
fontWeight: '400',
color: '#000',
fontSize: "12px"
}
},
marker: {
symbol: 'circle',
enabled: false
}
}
},
data: {
googleSpreadsheetKey: '13gjvlHhCZKlNcC1DV3nStGeWLBLWx3gxTO3SN9F3GQc',
complete: function(options) {
options.series[0].data.forEach(point => {
if (point[1] === 0) {
point[1] = null;
}
});
}
},
series: [{
color: '#8ebfd7',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: 'rgb(70, 151, 190)',
opacity: 0.5,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#266f9a',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#1c2b54',
opacity: 1,
dataLabels: {
enabled: true,
formatter: function() {
if (this.x == this.series.data[this.series.data.length - 1].x) {
return 'Test';
} else {
return null;
}
}
},
states: {
hover: {
opacity: 1
}
}
},
{
color: '#780081',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#9c00b3',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#b3007b',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#b30012',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#b36d00',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#b39c00',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#a3b300',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#59b300',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#12b36b',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#00b394',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#00a8b3',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#0091b3',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#373737',
name: 'Verdopplung alle 3 Tage',
clip: false,
dashStyle: 'dot',
showInLegend: false,
states: {
inactive: {
opacity: 1
}
},
}
]
});
I followed some instructions and tutorials online but failed to create a polar chart.
It ends up a normal line chart.
What's wrong with my code? Any tips?
Thanks,
Highcharts.chart('container', {
title: {
text: null
},
legend: {
enabled: false
},
tooltip: {
pointFormat: '{point.y}'
},
pane: {
size: '95%'
},
chart: {
type: 'area',
polar: true,
spacingTop: 0
},
credits: {
enabled: false
},
xAxis: {
categories: ["John","Weta","Marry"],
tickmarkPlacement: 'on',
lineWidth: 2,
labels: {
style: {
fontSize: window.screenshotMode ? '36px' : '18px'
}
}
},
yAxis: {
gridLineInterpolation: 'polygon',
lineWidth: 2,
min: 0,
max: 100,
labels: {
style: {
fontSize: window.screenshotMode ? '36px' : '18px'
}
}
},
plotOptions: {
series: {
borderWidth: 4,
borderColor: '#a00'
}
},
series: [{
data: [68,97,964]
}]
})
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container" style="height: 400px"></div>
highchart-more is required to run the polar charts so you will need to include highchart-more.js library.
<script src="https://code.highcharts.com/highcharts-more.js"></script>
Highcharts.chart('container', {
title: {
text: null
},
legend: {
enabled: false
},
tooltip: {
pointFormat: '{point.y}'
},
pane: {
size: '95%'
},
chart: {
type: 'area',
polar: true,
spacingTop: 0
},
credits: {
enabled: false
},
xAxis: {
categories: ["John","Weta","Marry"],
tickmarkPlacement: 'on',
lineWidth: 2,
labels: {
style: {
fontSize: window.screenshotMode ? '36px' : '18px'
}
}
},
yAxis: {
gridLineInterpolation: 'polygon',
lineWidth: 2,
min: 0,
max: 100,
labels: {
style: {
fontSize: window.screenshotMode ? '36px' : '18px'
}
}
},
plotOptions: {
series: {
borderWidth: 4,
borderColor: '#a00'
}
},
series: [{
data: [68,97,964]
}]
})
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<div id="container" style="height: 400px"></div>
API Reference : https://api.highcharts.com/highcharts/chart.polar
I have a bunch of HighCharts running data from Google Sheets, and some of them firstly render the plot area then keep reloading the data on the chart, and I can't figure out why. Is this just a HighCharts thing, or something I can fix?
This is what's happening https://youtu.be/ddM-WxCAczM
This is the Google Sheet I'm loading into HighCharts cloud https://docs.google.com/spreadsheets/d/e/2PACX-1vSQEXUaZFqT3Oatl3AK8S-bqq6vNs5vDjoG2puaFvQ7LsSGB5dIaBk0Kp2aHWE2lbFEms9gZ6r36TTQ/pubhtml
Here's the custom code I'm applying in HighCharts cloud to render the chart how I need it:
Highcharts.merge(true, options, {
chart: {
height: 445,
marginTop: 70,
spacingBottom:-100,
style: {
fontFamily: '"Trebuchet MS","Trebuchet","Helvetica","Lucida Sans Unicode","Lucida Sans",Tahoma,sans-serif',
},
events: {
load: function () {
this.update({
exporting: {
filename: this.options.title.text,
}
});
}
},
plotBorderColorLeft: '#ccc',
plotBorderWidth: 0,
backgroundColor: {
stops: [
[1, 'rgb(255, 255, 255)'],
]
}
},
plotOptions: {
column: {
pointPlacement: 'between'
},
series: {
marker: {
enabled: false,
},
cursor: 'arrow'
}
},
yAxis: {
plotLines: [{
color: '#010101',
width: 2,
value: 0,
zIndex: 5
}],
lineWidth: 1.5,
gridLineWidth: 0,
lineColor: '#010101',
tickWidth: 1.5,
tickLength: 4,
tickColor: '#010101',
title: {
align: 'high',
offset: -10,
text: '(%)',
rotation: 0,
y: -12,
style: {
fontSize: '14px'
},
},
labels: {
enabled: true,
style: {
fontSize: '13px'
}
},
startOnTick: true,
endOnTick: true,
tickInterval: 1,
tickPosition: 'inside',
tickmarkPlacement: 'on',
},
xAxis: {
title: {
text: 'Date',
style: {
display: 'none'
}
},
offset:-127,
useHTML: true,
labels: {
enabled: true,
rotation: -90,
x: 14,
style: {
fontSize: '16px'
},
y:160
},
lineWidth:2,
lineColor: '#010101',
tickWidth:2,
tickPosition: 'inside',
tickLength:4,
tickColor: '#010101',
tickmarkPlacement: 'on',
startOnTick: false,
endOnTick: false,
min:.0,
max:40.4
},
credits: {
enabled:false
},
legend: {
symbolRadius: 0,
floating:true,
itemStyle: {
font: '14px Trebuchet MS, Trebuchet, "Helvetica", Verdana, sans-serif',
color: '#010101'
},
itemMarginTop: 5,
floating: true,
layout: 'vertical',
align: 'left',
verticalAlign: 'top',
enabled: true,
x: 50,
y: 15
},
subtitle: {
style: {
display: 'none'
},
y: 0
},
title: {
style: {
display: 'none'
},
y: 0
},
tooltip: {
valueSuffix: '%'
},
exporting: {
buttons: {
contextButton: {
enabled: true,
y:-10,
x:10,
text: 'Download',
menuItems: [
"printChart",
"separator",
"downloadPNG",
"downloadJPEG",
"downloadPDF",
"downloadSVG",
"separator",
"downloadCSV",
"downloadXLS",
{
textKey: 'viewData',
text: 'Toggle data table',
onclick: function() {
if (this.dataTableDiv && this.dataTableDiv.style.display !== 'none') {
this.dataTableDiv.style.display = 'none';
} else {
this.viewData();
this.dataTableDiv.style.display = '';
}
}
}
]
}
}
}
});
Add Plugin 'angular2-highcharts'
add code in ionViewDidLoad()
var chart = Highcharts.mapChart('container', {
chart: {
map: 'custom/europe',
spacingBottom: 20
},
title: {
text: 'Europe time zones'
},
legend: {
enabled: true
},
plotOptions: {
map: {
allAreas: false,
dataLabels: {
enabled: true,
color: '#FFFFFF',
style: {
fontWeight: 'bold'
},
// Only show dataLabels for areas with high label rank
format: null,
formatter: function () {
if (this.point.properties && this.point.properties.labelrank.toString() < 5) {
return this.point.properties['iso-a2'];
}
}
},
tooltip: {
headerFormat: '',
pointFormat: '{point.name}: <b>{series.name}</b>'
}
}
},
})
I am having an issue displaying my chart. I am creating a script that displays three charts with a print button to print all the chart to one PDF.
The JSON call is returning:
[{"name":"Month"},{"name":"percent","data":[9.52]}]
I am not getting any errors in the browser console, can any one see where I am going wrong.
$(function () { //1
var chart1, chart2, chart3;
var categories=[];
//var chart;
var data2 =[];
$(document).ready(function() { //2
$.getJSON("../charts/1-2-4-detractors_month_chart.php?From=<?php echo $_GET['From'];?>&To=<?php echo $_GET['To'];?>", function(json) { //3
$.each(json,function(i,el) { //4
if (el.name=="Month")
categories = el.data;
else data2.push(el);
});
chart1 = new Highcharts.Chart({
chart: {
renderTo: 'container1',
type: 'column',
marginTop: 25,
marginRight: 25,
marginBottom: 25,
plotBackgroundColor: '#FCFFC5',
style: {
fontFamily: 'serif',
fontSize: '8px',
}
},
title: {
text: '',
},
subtitle: {
text: '',
},
xAxis: {
categories: categories,
labels: {
enabled: false
}
},
yAxis: {
endOnTick: false,
max:101,
showFirstLabel: false,
lineColor:'#999',
lineWidth:1,
tickColor:'#666',
tickWidth:1,
tickLength:2,
tickInterval: 10,
gridLineColor:'#ddd',
title: {
text: '',
style: {
fontFamily: 'Tahoma',
color: '#000000',
fontWeight: 'bold',
fontSize: '8px'
}
},
plotLines: [{
color: '#808080'
}]
},
legend: {
enabled: false,
},
colors: ['#FF0000','#FF2F2F'],
plotOptions: {
column: {
colorByPoint: true
},
series: {
cursor: 'pointer',
pointWidth: 20,
point: {
events: {
//click: function() {
//location.href = "feedback-items_detractors_iframe.php?FromDate1=<?php echo $StartDate;?>&ToDate1=<?php echo $EndDate;?> target='iframe2'";
//}
}
},
legendIndex:0,
dataLabels: {
enabled: true,
color: '#000000',
align: 'center',
cursor: 'pointer',
borderRadius: 5,
backgroundColor: 'rgba(252, 255, 255, 255)',
borderWidth: 1,
borderColor: '#AAA',
y: -6,
format: '{y:.2f} %', // one decimal
y: -20, // 10 pixels down from the top
style: {
textShadow: false,
fontSize: '8px',
fontFamily: 'Verdana, sans-serif'
}
}
}
},
tooltip: {
style: {
fontSize: '7pt',
fontFamily: 'Verdana, sans-serif'
},
valueDecimals: 1,
formatter: function() {
return '<b>Guest responses:<br/> '+ this.y +'%</b>';
}
},
navigation: {
buttonOptions: {
verticalAlign: 'top',
y: -10,
x: -20
}
},
credits: {
enabled: false
},
series: data2,
lang: {
noData: "No data"
},
noData: {
style: {
fontWeight: 'normal',
fontSize: '12px',
color: '#303030'
}
},
});
});
});
//});
//--------------------------------------------------------------------
$("#print").click(function () {
printCharts([chart1, chart2, chart3]);
});
//--------------------------------------------------------------------
function printCharts(charts) {
var origDisplay = [],
origParent = [],
body = document.body,
childNodes = body.childNodes;
// hide all body content
Highcharts.each(childNodes, function (node, i) {
if (node.nodeType === 1) {
origDisplay[i] = node.style.display;
node.style.display = "none";
}
});
// put the charts back in
$.each(charts, function (i, chart) {
origParent[i] = chart.container.parentNode;
body.appendChild(chart.container);
});
// print
window.print();
// allow the browser to prepare before reverting
setTimeout(function () {
// put the chart back in
$.each(charts, function (i, chart) {
origParent[i].appendChild(chart.container);
});
// restore all body content
Highcharts.each(childNodes, function (node, i) {
if (node.nodeType === 1) {
node.style.display = origDisplay[i];
}
});
}, 500);
}
});