Disable PDF and SVG download options in Highcharts - highcharts

I am using Highcharts v4.0.3 with exporting.js in my web app, and I want to be able to just provide the end user with the following download options:
Download Chart as JPG
Download Chart as PNG
However, the standard options are:
Print Chart
Download Chart as JPG
Download Chart as PNG
Download Chart as PDF
Download Chart as SVG Vector Graphic
How can I customise it so that it just gives the user JPG and PNG options?

You can manually set exporting.buttons.contextButton.menuItems (API) to contain whatever buttons you want.
You'll want to set it to only contain JPG and PNG like this (short form, textKey only):
menuItems: ['downloadPNG','downloadJPEG']
Or for more explicit function calls (long form with objects and onclick):
menuItems: [{
textKey: 'downloadPNG',
onclick: function () {
this.exportChart();
}
}, {
textKey: 'downloadJPEG',
onclick: function () {
this.exportChart({
type: 'image/jpeg'
});
}
}]
As in these JSFiddle demonstrations: short form and long form.
The default for exporting.js is:
menuItems: [{
textKey: 'printChart',
onclick: function () {
this.print();
}
}, {
separator: true
}, {
textKey: 'downloadPNG',
onclick: function () {
this.exportChart();
}
}, {
textKey: 'downloadJPEG',
onclick: function () {
this.exportChart({
type: 'image/jpeg'
});
}
}, {
textKey: 'downloadPDF',
onclick: function () {
this.exportChart({
type: 'application/pdf'
});
}
}, {
textKey: 'downloadSVG',
onclick: function () {
this.exportChart({
type: 'image/svg+xml'
});
}
}]
The additional ones for export-data.js are:
menuItems: [{
textKey: 'downloadCSV',
onclick: function () {
this.downloadCSV();
}
}, {
textKey: 'downloadXLS',
onclick: function () {
this.downloadXLS();
}
},{
textKey: 'viewData',
onclick: function () {
this.viewData();
}
},{
textKey: 'openInCloud',
onclick: function () {
this.openInCloud();
}
}]

You can remove unnecessary options the following way:
if (Highcharts.getOptions().exporting) {
let contextButton = Highcharts.getOptions().exporting.buttons.contextButton;
contextButton.menuItems = contextButton.menuItems.filter((item) => {
return item.textKey === 'downloadJPEG' || item.textKey === 'downloadPNG';
});
}

In chatOptions we can write customize options in the high-charts menu we can customize the dropdown options.
In chart options, we can write like:
exporting: {
buttons: {
contextButton: {
menuItems: ['downloadPNG', 'downloadJPEG', 'downloadPDF', 'downloadSVG'],
},
},
}
Example: click here
Reference: click here

Related

JQUERYUI: Modal buttons dont work when I close and open

I am creating a dialog in javascript and for some reason when I first open the dialog the buttons works fine. But when I close and open it the buttons dont work. The edit click function doesnt work the second time when I repopen the dialog
var newDiv = $(document.createElement('div'));
$(newDiv).dialog({
title: "New Dialog",
modal: true,
autoOpen: true,
width: 650,
height: 440,
resizable: false,
draggable: true,
buttons: [
{
html: "<b>Edit</font></b>",
icons: {
primary: "ui-icon-check"
},
click: function() {
$('#notetext').prop("disabled", false);
$('#uibtnSubmit').button("enable");
//$('#uibtnSubmit').prop("disabled", false);
//$("#uibtnSubmit").button().attr('disabled', false).removeClass('ui-state-disabled');
}},
{
html: "<b><font color='green'>Submit</font></b>",
disabled:true,
id: "uibtnSubmit",
icons: {
primary: "ui-icon-script"
},
click: function() {
var editnotes = $('#notetext').val();
//update the notes in the database against the user.
$.ajax({
type: "post",
cache: false,
async: false,
url:"url",
datatype: "json",
data: data,
success: function(data){
$(newDiv).dialog('close');
},
error: function(jqXHR, statusText, err){
//console.log(err);
}
});
}},
{
html: "<b><font color='red'>Exit</font></b>",
icons: {
primary: "ui-icon-cancel"
},
click: function() {
$(this).dialog('close');
}
}
]
});
I tried to use different properties like removeClass, attr but they arent working.
I solved the issue by reloading the page once Exit or submit value was clicked. That way when the dialog box was reloaded it was initialized.

Change data by download as pdf in Highcharts

i have a highchart and want to be able to download as pdf. But before downloading, to the highchart a title should be added as html. Is this possible? Like event:beforePrint and afterPrint, but just for downloading
You can define custom click event for the 'Download PDF document' button:
exporting: {
menuItemDefinitions: {
// Custom definition
downloadPDF: {
onclick: function() {
this.update({
title: {
text: 'New title'
}
}, false);
this.exportChart({
type: 'application/pdf'
});
this.update({
title: {
text: 'Old title'
}
}, false);
},
text: 'Download PDF document'
}
}
}
Live demo: http://jsfiddle.net/BlackLabel/02aw13ht/
API Reference:
https://api.highcharts.com/highcharts/exporting.menuItemDefinitions
https://api.highcharts.com/class-reference/Highcharts.Chart#update

Missing line on chart in popup

I wonder if anyone can see where I am going wrong. I am trying to get my line to appear on my chart in a popup. It works OK if I have the chart in a separate div but not in a popup. I am pulling data from Geoserver and I can see all the data fine. I am using leaflet and Highcharts.
Here is the relevant code.
var field_boundaries = L.tileLayer.wms("http://localhost:1997/geoserver/RSAC/wms", {
layers: 'RSAC:results_clipped_with_growth_small_new',
format: 'image/png',
transparent: true,
version: '1.1.0',
attribution: "myattribution"
});
//loads the geojson layer
var owsrootUrl = 'http://localhost:1997/geoserver/RSAC/wms';
var defaultParameters = {
service : 'WFS',
version : '1.1.0',
request : 'GetFeature',
typeName : 'RSAC:results_clipped_with_growth_small_new',
outputFormat : 'json',
format_options : 'callback:getJson',
SrsName : 'EPSG:4326'
};
var parameters = L.Util.extend(defaultParameters);
var URL = owsrootUrl + L.Util.getParamString(parameters);
var ajax = $.ajax({
url : URL,
dataType : 'json',
jsonpCallback : 'getJson',
success : function (response) {
new L.geoJson(response, {
onEachFeature: function (feature, url) {
// Create div with class name highchart
var div = L.DomUtil.create('div', 'highchart');
// Bind popup to layer with div as content
url.bindPopup(div);
// Handle event when popup opens
url.on('popupopen', function (e) {
console.log(e.target); // layer object
console.log(e.target.feature); // layer's feature object
console.log(e.popup); // popup object
console.log(e.popup.getContent()); // the div
$(".highchart").on('click', function onPopUpOpen(e){
$(".highchart")(e.popup.getContent(),{
chart: {
type: 'line',
renderTo: 'bindPopup'
},
title: {
text: 'Growth'
},
series: {
lineWidth:1,
colour: '#FF0000'
},
xAxis: {
allowDecimals: true,
categories: ['20151114', '20151126', '20151208', '20151220', '20160113', '20160125', '20160206', '20160218', '20160301', '20160313', '20160325', '20160406', '20160418', '20160430', '20160512', '20160524', '20160605', '20160629', '20160723', '20160804', '20160816'],
labels: {
formatter: function () {
return this.value;
}
}
},
yAxis: {
startOnTick: false,
minPadding: 0.05,
title: {
text: 'Crop Growth',
},
labels: {
formatter: function () {
return this.value;
}
}
},
tooltip: {
pointFormat: '{series.name}{point.y}'
},
plotOptions: {
line: {
dataLabels: {
enabled: false
},
enableMouseTracking: true
}
},
series: [{
cursor: 'pointer',
color: '#4D4D4D',
lineWidth: 3,
name: 'Growth',
data: [parseFloat(feature.properties.Date_20151114),parseFloat(feature.properties.Date_20151126),parseFloat(feature.properties.Date_20151208), parseFloat(feature.properties.Date_20151220), parseFloat(feature.properties.Date_20160113), parseFloat(feature.properties.Date_20160125), parseFloat(feature.properties.Date_20160206), parseFloat(feature.properties.Date_20160218), parseFloat(feature.properties.Date_20160301), parseFloat(feature.properties.Date_20160313), parseFloat(feature.properties.Date_20160325), parseFloat(feature.properties.Date_20160406), parseFloat(feature.properties.Date_20160418), parseFloat(feature.properties.Date_20160430), parseFloat(feature.properties.Date_20160512), parseFloat(feature.properties.Date_20160524), parseFloat(feature.properties.Date_20160605), parseFloat(feature.properties.Date_20160629), parseFloat(feature.properties.Date_20160723), parseFloat(feature.properties.Date_20160804), parseFloat(feature.properties.Date_20160816)]
},
]
});
// Create the chart
//var chart = new Highcharts.Chart(options);
});
}).addTo(mymap);
}
});
}
});

How can I add some html text to the highchart while exporting it to PNG, PDF,Jpeg?

I have used these options.
exporting: {
enabled: false,
allowHtml:true
}
This is my export function.
export(type: any) {
this.graph.exportChart({ type: type });
}
If you want only on export (add title) then use
Fiddle link
exporting: {
chartOptions: {
chart: {
events: {
load: function() {
var dynamic = document.getElementById('dynamic').value
this.setTitle({
text: dynamic
});
}
}
},
title: {
align: 'right',
}
}
},

Highcharts buttons with different menuitems not working

I am trying to create 2 export buttons (share & download) with two different menuItems in HighCharts
Button 1 (Share)
MenuItem 1: Share on Facebook
MenuItem 2: Share on Twitter
Button 2) Download
MenuItem 1: Print
MenuItem 2: Download as PNG
As you can see on http://jsfiddle.net/kmPh8/18/
exporting: {
buttons: [
{
text: 'Download',
x: -82,
symbolFill: '#B5C9DF',
hoverSymbolFill: 'red',
menuItems: [
{
text: 'Print',
onclick: function() {
alert('blue menu 1');
}
},
{
text: 'Download as PNG',
onclick: function() {
alert('blue menu10000');
}
}
]
},
{
text: 'Share',
x: -10,
symbolFill: '#B5C9DF',
hoverSymbolFill: 'blue',
menuItems: [{
text: 'Share on facebook',
onclick: function() {
alert('Facebook Share');
}},
{
text: 'Share on twitter',
onclick: function() {
alert('Twitter share');
}}
]}]
}
But... the problem is whatever button you click first you will see the menuItems on the second button, if you 'run' it again click the other button you will see the problem again. Each button basically doesn't show the individual menuitems.
Any help would be appreciated.
Indeed it looks like a problem, because I've tried to reproduce it here
http://jsfiddle.net/MzB9b/2/ and indeed issue is displayed.
exporting: {
buttons: {
contextButton: {
menuItems: [{
text: 'Export to PNG (small)',
onclick: function() {
alert('EXPORT PNG small');
}
}, {
text: 'Export to PNG (large)',
onclick: function() {
alert('EXPORT PNG large');
},
separator: false
}]
},
testButton: {
symbol: 'diamond',
x: -62,
symbolFill: '#B5C9DF',
hoverSymbolFill: '#779ABF',
_titleKey: 'printButtonTitle',
menuItems: [{
text: 'Facebook',
onclick: function() {
alert('Facebook');
},
}, {
text: 'Twitter',
onclick: function() {
alert('Twitter');
},
separator: false
}]
}
}
}
So I reported this problem to the developers https://github.com/highslide-software/highcharts.com/issues/1908

Resources