更新时间:2023-11-22 22:36:46
不幸的是,您有一些可视化图表固有的限制.即:
Unfortunately, you have some limitations inherent to the viz charts. Namely:
此外,您的 X 值 (AwDate) 是 字符串 形式的 ABAP 样式日期.使用日期/时间图表来正确显示它们更合适.无论如何,当您使用日期时,回归更有意义.否则,您的数据是分类的",您可以进行回归的唯一方法是对它们进行排序并考虑它们在 X 轴上等距 - 如果您拥有非等距数据(例如您的示例中的数据),则通常不需要.
Also, your X values (AwDate) are ABAP-style dates as string. It is more appropriate to use a date / time chart to correctly display them. Anyway, regression makes a lot more sense when you use dates. Otherwise your data is "categorical" and the only way you can make regression is by sorting them and considering them equidistant on the X axis - not what you would normally want if you have non-equidistant data (like the one in your example).
我的建议是:
根据要求,我在这里做了一个示例实现:https://jsfiddle.net/93mx0yvt/23/.我从这里借用的回归算法:https://dracoblue.net/dev/linear-least-squares-in-javascript/.代码的要点是:
As requested, I made an example implementation here: https://jsfiddle.net/93mx0yvt/23/. The regression algorithm I borrowed from here: https://dracoblue.net/dev/linear-least-squares-in-javascript/. The main points of the code are:
// format for parsing the ABAP-style dates
var oFormat = DateFormat.getDateInstance({
pattern: "yyyyMMdd"
});
// maps an ProductCollection entry to a new object
// which has the parsed date (and only the needed attributes)
var fnMapData = function(oEntry) {
return {
date: oFormat.parse(oEntry.AwdDate),
current: oEntry.Current,
historical: oEntry.Hist
};
};
var fnProcessData = function(oD) {
var aEntries = oD.ProductCollection.map(fnMapData),
aXs = aEntries.map(function(oE) { // get the Xs
// we take the millis to be able to do arithmetics
return oE.date.getTime();
}),
aYs = aEntries.map(function(oE) { // get the Ys (hist)
return oE.historical;
}),
//changed the function to only return only result Ys
aRs = findLineByLeastSquares(aXs, aYs);
//save the Ys into the result
for (var i = 0; i < aEntries.length; ++i) {
aEntries[i].trend = aRs[i];
}
return {
data: aEntries
};
};
然后您可以在 JSONModel 中使用 fnProcessData
函数返回的数据,然后基于它构建一个简单的多系列日期/时间折线图.
You can use then the data returned by the fnProcessData
function inside a JSONModel and then build a simple multi-series date/time line chart based on it.