Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Client Side Exporting in Highchart

DZone's Guide to

Client Side Exporting in Highchart

This article tackles the idea and code of client-side exporting in HighChart.

· Web Dev Zone
Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

In this post we will discuss how we can enable client-side exporting in HighChart. Normally, the data of your chart is sent to the external server here. But if your product is already in the production environment, your clients will agree with the idea of sending their data to any third party server. Am I right? To overcome this, HighChart has given an option called offline-exporting. We will discuss that here.

For starters, there is a demo here.

Background

For the past few months, I have been working with a project where I use HighChart to manipulate data and show them as Charts. Now the problem is while exporting the data, all of it was going to the HighChart server. I wanted to get rid of this. So, I used the option client-side exporting by adding one extra JavaScript file: https://code.highcharts.com/modules/offline-exporting.js.

Using the code

First, we will populate the chart. For that, you have to add the needed references as follows:

<script src="https://code.jquery.com/jquery-2.2.4.min.js""></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

Now, add the chart configuration as follows:

$(function () {
 $('#myChart').highcharts({
 credits: {
 enabled: false
 },
 exporting: {
 chartOptions: {
 plotOptions: {
 series: {
 dataLabels: {
 enabled: true
 }
 }
 }
 },
 scale: 3
 },
 title: {
 text: 'My blog vistor count for a week'
 },
 subtitle: {
 text: 'Monday to Sunday'
 },
 chart: {
 type: 'area'
 },
 xAxis: {
 categories: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat',
 'Sun']
 },
 series: [{
 name:'Visitor Count',
 data: [1005, 558, 1467, 707, 1289, 867, 543]
 }]
 });
});

Now, if you run your application, you can see a chart as follows:

High Chart

Now it's time to check the exporting. If you click on export icon on the right top corner, you will see options such as which format you need to export the data. Just click on anything you wish. You can see that the data is being seny to the server in the top left. To overcome this, you need to add a reference of the file called offline-exporting.js.

<script src="https://code.highcharts.com/modules/offline-exporting.js"></script>

That’s it. You are done.

Please note that this feature is not supported in browser IE 8, so if you load this chart in any unsupported browser, the module will fall back to the export server. This can be handled with the option fallbackToExportServer: false. You need to set this option in your exporting settings as follows:

exporting: {
 chartOptions: {
 plotOptions: {
 series: {
 dataLabels: {
 enabled: true
 }
 }
 }
 },
 scale: 3,
 fallbackToExportServer: false
 }

In Internet Explorer, it requires a canvg library to export the chart to PNG format. But you don’t need to worry about this file. The system will automatically download it file on demand.

For more information, here is a reference for client side exporting.

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:
server ,external server ,javascript ,client ,party

Published at DZone with permission of Sibeesh Venu, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}