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
Related
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.
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
Is it possible to format the exporting "contextButton" in Highcharts? (Specifically to look more like other buttons on a page.) I do not mean creating a new button with new functionality, I mean the exact functionality of the standard exporting contextButton, I just want to change basic css like colors. Thanks.
exporting: {
enabled: true,
buttons: {
contextButton: {
text: 'Export',
color: '#f00', // this does nothing
},
},
The documentation for the context button is at...
http://api.highcharts.com/highcharts#exporting.buttons.contextButton
If you want to change the color of the symbol on the button then use the symbol attributes. For example...
exporting: {
enabled: true,
buttons: {
contextButton: {
text: 'Export',
symbolFill: '#f88',
symbolStroke: '#f00'
}
}
}
If you want to change the color of the button then use the theme attribute. For example...
exporting: {
enabled: true,
buttons: {
contextButton: {
text: 'Export',
theme: {
fill: '#ddd',
stroke: '#888',
states: {
hover: {
fill: '#fcc',
stroke: '#f00'
},
select: {
fill: '#cfc',
stroke: '#0f0'
}
}
}
}
}
}
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
I am using Jqgrid in my application. I wanted to create a column with 2 buttons. I want to have in column since the buttons may differ based on the data of the row. I googled it and I am able to found only creating a button using custom formatter option, but it appears only on double clicking a row or on edit of a row, but I want it to be displayed on column itself. Any help or link containing information will be appreciated. Below is my grid code.
Need to create an another column with buttons.
Edit:
var grid = $(gridId);
grid.jqGrid({
data: gridData,
datatype: "local",
gridview: true,
colModel: [
{
label: 'Employee Name', name: 'employeeName', width: 195, editable:true,
sortable:true, editrules:{required:true}
},
{
label: 'Address', name: 'address', width: 170, editable:true,
sortable:true,
editrules:{required:true}
},
{
label: 'Department', name: 'department', width: 120, editable:true,
sortable:true,
edittype:'custom',
editoptions: {
'custom_element' : populateReturnTypeAutocomplete,
'custom_value' : autocomplete_value
},
editrules:{required:true}
},
});
Okay add this to your colModal
{label: 'My Custom Column', name: 'custom', index:'custom' width: 120}
Now in gridComplete or loadComplete add this code
var grid = $("#grid"),
iCol = getColumnIndexByName(grid,'custom'); // 'custom' - name of the actions column
grid.children("tbody")
.children("tr.jqgrow")
.children("td:nth-child("+(iCol+1)+")")
.each(function() {
$("<div>",
{
title: "button1",
mouseover: function() {
$(this).addClass('ui-state-hover');
},
mouseout: function() {
$(this).removeClass('ui-state-hover');
},
click:
handle your click function here
}
).css({"margin-left": "5px", float:"left"})
.addClass("ui-pg-div ui-inline-save")
.attr('id',"customId")
.append('<span class="ui-button-icon-primary ui-icon ui-icon-disk"></span>')
.appendTo($(this).children("div"));
$("<div>",
{
title: "custombutton 2",
mouseover: function() {
$(this).addClass('ui-state-hover');
},
mouseout: function() {
$(this).removeClass('ui-state-hover');
},
click:
handle click here
}
).css({"margin-left": "5px", float:"left"})
.addClass("ui-pg-div ui-inline-custom")
.attr('id',"customButton2")
.append('<span class="ui-button-icon-primary ui-icon ui-icon-circle-check"></span>')
.appendTo($(this).children("div"));
Now these icons I'm adding here will be available with jquery ui.css and you will have to add one more function to your script which will get 'custom' column index for u in line first of above code.
var getColumnIndexByName = function(grid,columnName) {
var cm = grid.jqGrid('getGridParam','colModel'), i=0,l=cm.length;
for (; i<l; i+=1) {
if (cm[i].name===columnName) {
return i; // return the index
}
}
return -1;
};
I hope this helps.