JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<div id="chartContainer" style="height: 300px; width: 100%;">
</div>
JavaScript
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer",
{
title: {
text: "Chart with export feature enabled",
},
exportEnabled: true,
axisX:{
minimum: -900,
interval: 100,
},
data: [
{
type: "area",
fillOpacity: .4,
lineThickness: 3,
dataPoints: [
{ x: -100, y: 71 },
{ x: -200, y: 55 },
{ x: -300, y: 50 },
{ x: -400, y: 65 },
{ x: -500, y: 105 },
{ x: -600, y: 68 },
{ x: -700, y: 28 },
{ x: -800, y: 34 },
{ x: -900, y: 14}
]
}
]
});
chart.render();
//create div to add on export options.
var exportButton = jQuery("<div/>");
exportButton.text("Export");
exportButton.attr("style",jQuery(".canvasjs-chart-toolbar div div")[0].getAttribute("style"));
// add click event to the button to export the chart.
exportButton.on("click", function(e) {
for(var i = 0; i < chart.options.data.length; i++) {
chart.options.data[i].indexLabel = "{x}: {y}";
}
chart.render();
chart.exportChart({format: "jpg"});
for(var i = 0; i < chart.options.data.length; i++) {
chart.options.data[i].indexLabel = "";
}
chart.render();
});
// remove all the options from the exportEnabled options
jQuery(".canvasjs-chart-toolbar div div").remove();
exportButton.appendTo(jQuery(".canvasjs-chart-toolbar div"));
}