Highstock export csv based on data grouping(基于数据分组的Highstock出口CSV)
本文介绍了基于数据分组的Highstock出口CSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何修改此代码以使其基于data grouping
生成csv
数据
(function( Highcharts ) {
'use strict';
Highcharts.Chart.prototype.downloadCSV = function( returnOutput ) {
var titles = [],
xValues = [],
line,
csv = "",
col,
options = (this.options.exporting || {}).csv || {},
totalSeries = 0,
xNeedsSorting = false,
// Options
dateFormat = options.dateFormat || '%d-%m-%Y',
itemDelimeter = options.itemDelimeter || ',',
url = options.url || '/service/Export/exportchartcsv.php',
lineDelimiter = options.lineDelimeter || '
';
Highcharts.each(this.series, function( series, seriesNo ) {
if ( series.options.includeInCSVExport === true ) return;
if ( series.options.xAxis ) { // if option is set and not zero
alert("Downloading charts as CSV with multiple axes is no supported, sorry.");
throw false;
}
if ( titles.length === 0 ) {
var xTitle = ((series.xAxis.options || {}).title || {}).text;
if ( xTitle ) {
// series.xAxis.title.text exists and we use it
} else if ( series.xAxis.isDatetimeAxis ) {
xTitle = "RGF0ZSAvIFRpbWU=";
xNeedsSorting = true;
} else if ( series.xAxis.categories ) {
xTitle = "Q2F0ZWdvcnk=";
} else {
xTitle = "WCB2YWx1ZXM=";
}
titles.push(xTitle);
}
titles.push(series.name.replace(/[^a-z0-9s]/gi, '-'));
totalSeries++;
});
Highcharts.each(this.series, function( series, seriesNo ) {
if ( series.options.includeInCSVExport === true ) return;
//console.log(series.options.alternateData);
Highcharts.each(series.options.alternateData, function( point ) {
var l = xValues.length;
while ( l-- ) {
if ( xValues[l].x === point[0] ) {
xValues[l].y[seriesNo] = point[1];
return;
}
}
var y = new Array(totalSeries);
y[-1] = point[0]; // -1nth element holds formatted x axis value
y[seriesNo] = point[1];
if ( series.xAxis.isDatetimeAxis ) {
y[-1] = Highcharts.dateFormat(dateFormat, point[0]);
} else if ( series.xAxis.categories ) {
y[-1] = Highcharts.pick(series.xAxis.categories[point[0]], point[0]);
}
xValues.push({ x : point[0], y : y });
})
});
if ( xNeedsSorting ) {
xValues.sort(function( a, b ) {return a.x - b.x});
}
csv = titles.join(itemDelimeter) + lineDelimiter;
Highcharts.each(xValues, function( values ) {
line = [];
for ( col = -1; col < values.y.length; col++ ) {
line.push(values.y[col]);
}
csv += line.join(itemDelimeter) + lineDelimiter;
});
if ( returnOutput ) {
return csv;
} else {
var title = ((this.title || {}).text || 'chart') + '.csv',
a = document.createElement('a');
if ( "download" in a ) { // modern browser - no need to use backend script
a.href = 'data:attachment/csv,' + encodeURIComponent(csv);
a.target = '_blank';
a.download = title;
document.body.appendChild(a);
a.click();
a.remove();
} else {
Highcharts.post(url, { csv : csv, title : title });
}
}
};
Highcharts.Chart.prototype.getCSV = function() {
return this.downloadCSV(true);
};
// Now we want to add "Download CSV" to the exporting menu. We post the CSV
// to a simple PHP script that returns it with a content-type header as a
// downloadable file.
// The source code for the PHP script can be viewed at
// https://raw.github.com/highslide-software/highcharts.com/master/studies/csv-export/csv.php
if ( Highcharts.getOptions().exporting ) {
Highcharts.getOptions().exporting.buttons.contextButton.menuItems.push({
text : Highcharts.getOptions().lang.downloadCSV || "Export Data",
onclick : function() { this.downloadCSV() }
});
}
}(Highcharts));
推荐答案
首先,您使用的是用于HighChart的旧版本的EXPORT-csv,js插件。从gitHub下载实际版本。
然后在#31和#47行中您将看到series.xData.slice()
/series.yData.slice()
。这些数组包含原始的x/y值。如果在数据分组后需要值(当应用近似值时),则将x/yData更改为x/yProcessedXData:
series.processedXData.slice();
series.processedYData.slice();
这篇关于基于数据分组的Highstock出口CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:基于数据分组的Highstock出口CSV


猜你喜欢
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01