Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

highcharts : set title on exporting

I'm looking a way to:

  • hide title on the HTML page result
  • show title on the highcharts graph when I export it (PDF,PNG,JPEG or print)

I don't know how to proceed. There is someone able to help me?

like image 978
user2050723 Avatar asked Feb 07 '13 12:02

user2050723


2 Answers

You can define this parameter in exporting.

http://api.highcharts.com/highcharts#exporting.chartOptions

http://jsfiddle.net/BdHJM/

exporting:{
            chartOptions:{
                title: {
                    text:'aaaaa'
                }
            }
        },
like image 103
Sebastian Bochan Avatar answered Sep 29 '22 07:09

Sebastian Bochan


put this function in your document ready function below is a code for changing highcharts print prototype and just for the patch or to make it work put rangeSelector option in your exporting and set it to false as mentioned below you can set it to your needs in future

     Highcharts.wrap(Highcharts.Chart.prototype, 'print', function (proceed) {

                    var applyMethod = function (whatToDo, margin) {
                    this.extraTopMargin = margin;
                    this.resetMargins();
                    this.setSize(this.container.clientWidth , this.container.clientHeight , false);

                    this.setTitle(null, { text: 'SET TITLE HERE' :'});

                    this.rangeSelector.zoomText[whatToDo]();
                    $.each(this.rangeSelector.buttons, function (index, button) {
                        button[whatToDo]();
                    });
                };
                if (this.rangeSelector) {
                    var extraMargin = this.extraTopMargin;
                    applyMethod.apply(this, ['hide', null]);
                    var returnValue = proceed.call(this);
                    applyMethod.apply(this, ['show', extraMargin]);
                    this.setTitle(null, { text: '' });
                } else {
                    return proceed.call(this);
                    this.setTitle(null, { text: '' });
                    this.yAxis[0].setExtremes();
                }                       }


    });

and in chart option set this (change it according to you need to, i am just putting my code for reference )

     exporting: {
            scale: 1,
            sourceWidth: 1600,
            sourceHeight: 900,

            chartOptions: {
                rangeSelector: {
                    enabled: false
            },
    }
like image 38
Madhav Avatar answered Sep 29 '22 08:09

Madhav