Can't get csv from Highcharts -
i want create possible download csv-file highchart ... in example.
link jsfiddle
i've tried implement it, doesnt work in code .... reason? i want alert csv! later want implement can download ...
here code:
<script language="javascript" type="text/javascript" src="../js/jquery-1.8.3.js"> </script> <script language="javascript" type="text/javascript" src="../js/jquery-ui-1.9.2.custom.js"</script> <script src="../js/highcharts.js "></script> <script src="../js/exporting.js "></script> <script src="../js/exporting.src.js "></script> <link rel="stylesheet" href="../css/jquery-ui-1.9.2.custom.css" type="text/css" /> <script type="text/javascript"> (function (highcharts) { var each = highcharts.each; highcharts.chart.prototype.getcsv = function () { var xaxis = this.xaxis[0], columns = [], line, csv = "", row, col; if (xaxis.categories) { columns.push(xaxis.categories); columns[0].unshift(""); } each (this.series, function (series) { columns.push(series.ydata); columns[columns.length - 1].unshift(series.name); }); // transform columns csv (row = 0; row < columns[0].length; row++) { line = []; (col = 0; col < columns.length; col++) { line.push(columns[col][row]); } csv += line.join(',') + '\n'; } homecoming csv; }; }(highcharts)); $(function () { $(document).ready(function() { chart = new highcharts.chart({ chart: { renderto: 'container', type: 'pie' , }, title: { text: 'top 5 powerfulness consumer overall' }, yaxis: { title: { text: ' ', } }, legend: { enabled: false }, series: [{ name: 'work', data:[1,2,3,4,5] }], }); }); }); $('#getcsv').click(function () { alert(chart.getcsv()); }); </script> </head> <body> <div id="container"></div> <button id="getcsv" > alert </button> </body> </html>
your code working:
for download cvs add together code block:
highcharts.getoptions().exporting.buttons.exportbutton.menuitems.push({ text: 'download csv', onclick: function () { highcharts.post('http://www.highcharts.com/studies/csv-export/csv.php', { csv: this.getcsv() }); } });
your code demo
highcharts
No comments:
Post a Comment