I am using two instance of high chart(Highcharts.JS v4.1.6) parallel, but when i tried to print the chart using export functionality, another chart gets invisible when print command gets completed.
Chart configuration:
var chart1, chart2;
var options, options2;
options = {
title: {
text: '',
floating: true,
align: 'left',
width: 610,
style: {
fontSize: '1.4em'
}
},
chart: {
renderTo: 'content1',
type: 'bar',
marginLeft: 210,
marginTop: 80,
spacingBottom: 15,
spacingLeft: 10,
spacingRight: 10
},
credits: {
enabled: false
},
credits: {
text: 'Source: xxxx',
href: '',
position: {
align: 'right',
x: -30,
y: -3
}
},
exporting: {
buttons: {
contextButton: {
align: 'right',
x: 2,
y: 10,
text: 'Download',
verticalAlign: 'top'
}
}
},
xAxis: {
categories: [],
labels: {
step: 1,
enabled: true,
formatter: function() {
var text = this.value,
formatted = text.length > 25 ? text.substring(0, 30) : text;
return '<div class="js-ellipse" style="width:150px; overflow:hidden" title="' + text + '">' + formatted + '</div>';
},
style: {
fontSize: '12px'
}
}
},
yAxis: {
max: 100,
plotLines: [{
color: 'black',
dashStyle: 'Solid',
value: 0,
width: 2
}, {
color: 'black',
width: 2,
value: 50
}
],
title: {
text: ''
},
},
legend: {
itemStyle: {
color: '#000000',
fontWeight: ''
},
layout: 'horizontal',
align: 'center',
x: 1,
verticalAlign: 'top',
y: 35,
floating: true,
backgroundColor: '#FFFFFF',
reversed: true
},
tooltip: {
style: {
padding: 30
},
formatter: function() {
return '' +
'<strong>' + this.x + '</strong><br>' + this.series.name + ': ' + Highcharts.numberFormat(this.y, 1) + "%";
}
},
plotOptions: {
series: {
grouping: true,
pointPadding: 0,
borderWidth: 0,
dataLabels: {
enabled: true,
crop: false,
formatter: function() {
return this.y.toFixed(1);
}
}
}
},
series: [],
}
options2 = {
title: {
text: ''
},
chart: {
renderTo: 'content2',
type: 'bar',
spacingBottom: 15,
spacingLeft: 10,
spacingRight: 10,
marginTop: 80
},
credits: {
text: 'Source: xxx',
href: '',
position: {
align: 'right',
x: -30,
y: -3
}
},
exporting: {
buttons: {
contextButton: {
align: 'right',
x: 2,
y: 10,
text: 'Download',
verticalAlign: 'top'
}
}
},
xAxis: {
categories: [],
labels: {
enabled: false,
step: 1,
overflow: 'justify',
crop: false,
formatter: function() {
var text = this.value,
formatted = text.length > 25 ? text.substring(0, 30) : text;
return '<div class="js-ellipse" style="width:150px; overflow:hidden" title="' + text + '">' + formatted + '</div>';
},
style: {
fontSize: '12px'
}
}
},
yAxis: {
plotLines: [{
color: 'black',
dashStyle: 'Solid',
value: 0,
width: 2
}],
title: {
text: ''
},
},
legend: {
itemStyle: {
color: '#000000',
fontWeight: ''
},
layout: 'horizontal',
align: 'center',
x: 1,
verticalAlign: 'top',
y: 35,
floating: true,
backgroundColor: '#FFFFFF',
reversed: true
},
tooltip: {
style: {
padding: 30
},
formatter: function() {
return '' +
'<strong>' + this.x + '</strong><br>' + this.series.name + ': ' + Highcharts.numberFormat(this.y, 1) + "%";
}
},
plotOptions: {
series: {
dataLabels: {
enabled: true,
crop: false,
formatter: function() {
return this.y.toFixed(1);
}
}
}
},
series: [],
}
Before Print chart:
After Print when left side chart export print button used:
After Print when right side chart export print button used:
This will happen when print chart is used otherwise it work well.I couldn't figure out the issue.Please help me.
Thanks.
I have refer the below code that resolved my issue.
var beforePrint = function()
{
chart1 = jQuery('#content1').highcharts();
chartWidth1 = chart1.chartWidth;
chartHeight1 = chart1.chartHeight;
chart1.setSize(578,chartHeight1, false);
chart2 = jQuery('#content2').highcharts();
chartWidth2 = chart2.chartWidth;
chartHeight2 = chart2.chartHeight;
chart2.setSize(405,chartHeight2, false);
};
var afterPrint = function() {
chart1.setSize(chartWidth1,chartHeight1, false);
chart1.hasUserSize = null; // This makes chart responsive
chart2.setSize(chartWidth2,chartHeight2, false);
chart2.hasUserSize = null; // This makes chart responsive
};
if (window.matchMedia) {
var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function(mql) {
if (mql.matches) {
beforePrint();
} else {
afterPrint();
}
});
}
window.onbeforeprint = beforePrint;
window.onafterprint = afterPrint;
Related
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 = '';
}
}
}
]
}
}
}
});
I have a script that returns a chart (Highcharts) and it works fine apart from not displaying the names of the columns on the x axis. Can anyone see where I have gone wrong.
My Json:
[{"data":[30.95]},{"data":[2.38]},{"data":[66.67]}]
My script:
$(function () {
var colors = ['#FF0000','#FF9900','#009900'];
colorIterator = 0;
var chart;
$(document).ready(function() {
$.getJSON("../charts/1-2-4-reports_chart.php?TAG=<?php echo $_POST['SectionVar'];?>&From=<?php echo $StartDate;?>&To=<?php echo $EndDate;?>", function(json) {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container1',
type: 'column',
height: 200,
marginRight: 25,
marginBottom: 25,
plotBackgroundColor: '#FCFFC5',
style: {
fontFamily: 'serif',
fontSize: '8px',
}
},
title: {
text: 'Net Promoter Score: <?php echo $_POST['SectionVar'];?>',
x: -20,
style: {
fontFamily: 'Tahoma',
color: '#000000',
fontWeight: 'normal',
fontSize: '11px'
} //center
},
subtitle: {
text: '',
},
xAxis: {
categories: ['Detractors', 'Passives', 'Promoters'],
title: {
text: ''
}
},
yAxis: {
//reversedStacks: false,
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'
}]
},
credits: {
enabled: false
},
tooltip: {
formatter: function() {
return '<b>Guest responses: '+ this.y +'<br/>'+ this.series.name +'</b><br/>Month:'+
this.x;
}
},
navigation: {
buttonOptions: {
verticalAlign: 'top',
y: -10,
x: -20
}
},
legend: {
enabled: false,
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 1
},
colors: [
'#FF0000',
'#FF9900',
'#009900',
],
plotOptions: {
column: {
colorByPoint: false
},
series: {
type: 'column',
cursor: 'pointer',
pointWidth: 30,
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
this.series.name
style: {
textShadow: false,
fontSize: '8px',
fontFamily: 'Verdana, sans-serif'
}
}
}
},
exporting: {
chartOptions: { // specific options for the exported image
plotOptions: {
series: {
dataLabels: {
enabled: true
}
}
}
},
fallbackToExportServer: false
},
series: json,
});
});
});
});
Many thanks in advance for your time.
You made some syntax errors in your code, fixed version below:
$(function() {
var colors = ['#FF0000', '#FF9900', '#009900'];
var colorIterator = 0;
var chart;
$(document).ready(function() {
const json = [{"data":[30.95]},{"data":[2.38]},{"data":[66.67]}]
setTimeout(function() {
chart = Highcharts.chart('container', {
chart: {
renderTo: 'container1',
type: 'column',
height: 200,
marginRight: 25,
marginBottom: 25,
plotBackgroundColor: '#FCFFC5',
style: {
fontFamily: 'serif',
fontSize: '8px',
}
},
title: {
text: '',
x: -20,
style: {
fontFamily: 'Tahoma',
color: '#000000',
fontWeight: 'normal',
fontSize: '11px'
} //center
},
subtitle: {
text: '',
},
xAxis: {
categories: ['Detractors', 'Passives', 'Promoters'],
title: {
text: ''
}
},
yAxis: {
//reversedStacks: false,
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'
}]
},
credits: {
enabled: false
},
tooltip: {
formatter: function() {
return '<b>Guest responses: ' + this.y + '<br/>' + this.series.name + '</b><br/>Month:' +
this.x;
}
},
navigation: {
buttonOptions: {
verticalAlign: 'top',
y: -10,
x: -20
}
},
legend: {
enabled: false,
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 1
},
colors: [
'#FF0000',
'#FF9900',
'#009900',
],
plotOptions: {
column: {
colorByPoint: false
}
},
series: {
type: 'column',
cursor: 'pointer',
pointWidth: 30,
point: {
events: {
}
},
legendIndex: 0,
dataLabels: {
enabled: true,
color: '#000000',
align: 'center',
cursor: 'pointer',
y: -6,
format: '{y:.2f} %', // one decimal
y: -20, // 10 pixels down from the top
style: {
textShadow: false,
fontSize: '8px',
fontFamily: 'Verdana, sans-serif'
}
}
},
exporting: {
chartOptions: { // specific options for the exported image
plotOptions: {
series: {
dataLabels: {
enabled: true
}
}
}
},
fallbackToExportServer: false
},
series: json,
});
});
});
});
https://jsfiddle.net/0kjojak9/
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);
}
});
I am using HighCharts to ploot some graph. I want my y-aixs to range between -1 to +1. When i set max=1 and min=-1 for y-axis, it does not work. Is there another way of implementing this. Below is the my code example.
$(opts.containerSelector).find('.chart-container').highcharts({
chart: {
events: {
load: loadLegendSelection
},
},
plotOptions: {
area: {
fillOpacity: 0.7
},
spline: {
marker: {
radius: 3
}
},
series: {
events: {
legendItemClick: storeLegendSelection
}
}
},
legend: {
},
loading: {
labelStyle: { "position": "relative", "top": "45%", "font-weight": "300", "color": "#29303a", "font-size": "22px" }
},
xAxis: {
gridLineDashStyle: 'dash',
gridLineColor: '#c2dce6',
gridLineWidth: 1,
min: minDate,
max: maxDate,
type: 'datetime',
labels: {
formatter: function() {
return formatTimestampTime(this.value);
}
},
events : {
afterSetExtremes : afterSetExtremes.bind(this, opts)
},
minRange: 3600 // one minute
},
yAxis: {
max: 1,
min: -1,
endOnTick: false,
gridLineDashStyle: 'dash',
gridLineColor: '#c2dce6',
gridLineWidth: 1,
labels: {
formatter: function() {
return formatMegawatts(this.value);
}
},
showFirstLabel: false,
title: ''
},
series: convertedData,
exporting: {
enabled: false
},
credits: {
enabled: false
},
tooltip: {
formatter:
function() {
return '<b>' + formatTimestampDateTimeWithSeconds(this.x) + '</b><br>' + formatMegawatts(this.y) + ' ('+ this.series.name + ')';
}
}
});
you can try setting min and max as given below.
yAxis: [{
max:1,
min: -1,
allowDecimals: false,
endOnTick: false,
gridLineWidth: 0,
labels: {
style: {
color: '#767676'
}
},
offset: -10,
title: {
text: 'Inv ' + val_qty,
"textAlign": 'top',
"rotation": 0,
x: 60,
y: yaxisVal,
style: {
color: '#767676',
fontWeight: 'bold'
}
}
}, {
allowDecimals: false,
min: 0,
endOnTick: false,
gridLineWidth: 0,
title: {
text: y2axisname,
"textAlign": 'top',
"rotation": 0,
x: -75,
y: yaxisVal,
style: {
color: '#767676',
fontWeight: 'bold'
}
},
offset: -10,
labels: {
format: '{value}',
style: {
color: '#767676'
}
},
opposite: true
}],
Is it possible to start the line from the hinges base ?
I have looked everywhere and couldnt find a solution for it
here is my code
jQuery('#chart').highcharts({
colors: ['#f5781e', '#7b3186'],
navigation: {
buttonOptions: {
enabled: false
}
},
credits: {
enabled: false
},
chart: {
type: 'line',
marginRight: 0,
marginBottom: 35,
width: 700,
height: 280,
},
title: {
text: '',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
xAxis: {
categories: ['1','2','3','4','5','6','7','8'],
alternateGridColor: '#f4f6f5',
lineColor: '#000000',
lineWidth: 1,
min: 0,
},
yAxis: {
title: {
text: ''
},
labels: {
useHTML : true,
format: '<span class="axis"><span class="flright">{value}</span>אלף</span>'
},
tickInterval: 3,
max: 35.2,
plotLines: [{
value: 1,
width: 1,
color: '#000'
}],
lineColor: '#000000',
lineWidth: 1,
min: 0
},
plotOptions: {
series: {
pointStart: 0
}
},
tooltip: {
crosshairs: {
width: 2,
color: 'gray',
dashStyle: 'shortdot'
},
animation: true,
valueSuffix: ',000₪',
backgroundColor: 'rgba(255, 255, 255, 0.8)',
formatter: function() {return '<b>₪' + this.x + this.y +'</b>';}
},
legend: {
enabled: false
/*****************
layout: 'horizontal',
align: 'center',
verticalAlign: 'bottom',
borderWidth: 0,
floating: true,
rtl: true,
y: 15,
margin: 10,
useHTML: true,
itemStyle: {
fontFamily: 'Arial, Helvetica, sans-serif',
fontWeight: 'bold'
}
*******************/
},
series: [
{
name: 'b',
data: [0.5,1,1.5,2,2.5,3,3.5,4]
},
{
name: '<span class="abc">a</span>',
data: [4,8,12,16,20,24,28,32]
}
]
},function(chart) { //LOGO
chart.renderer.image('/images/small_logo.png', 670, 18, 31, 23).add();
}
);
here is an image of what i want to achieve
You just have to change you min value :
xAxis: {
...
min: 0.5,
...
},
Look at this : http://jsfiddle.net/yKHsD/
EDIT :
There is a better solution. It is caused by the categories option. You can avoid this problem by doing :
var xCategories = ['1','2','3','4','5','6','7','8'];
// ...
xAxis: {
....
tickmarkPlacement: 'on',
labels: {
formatter: function() {
return xCategories[this.value];
}
},
startOnTick: false,
endOnTick: false,
minPadding: 0,
maxPadding: 0,
gridLineWidth: 1
},
In this example, don't forget to remove the categories option. Here is an example : http://jsfiddle.net/yKHsD/1/