2
如何找到两个系列(Keen.Series)之间的差异,然后将它绘制在折线图上?Keen IO - 如何找到两个Keen.Series之间的区别
我想出了如何找到两个度量(Keen.Metric)之间的差异,但无法弄清楚如何从两个系列中获取每个结果并相应地减去它们。
如果这会有所帮助,这里是如何找到这两个指标之间的区别:
Keen.onChartsReady(function(){
// Create a Metric containing our total $ amount in Keen IO credit card transactions (to and from)
// Excludes: refund transactions from Stripe to card and declined cards
var myMetric = new Keen.Metric("Stripe_Event",
analysisType: "sum",
targetProperty: "data.object.amount",
filters: [
{"property_name":"data.object.captured","operator":"eq","property_value":true},
{"property_name":"data.object.amount_refunded","operator":"eq","property_value":0}]
});
// Create a Metric containing our total number of refunds
var myMetric2 = new Keen.Metric("Stripe_Event", {
analysisType: "sum",
targetProperty: "data.object.amount_refunded",
filters: [
{"property_name":"type","operator":"eq","property_value":"charge.refunded"}]
});
// Find the difference and convert to dollars
myMetric.getResponse(function(response){
firstValue = response.result;
myMetric2.getResponse(function(nextResponse){
secondValue = nextResponse.result;
difference = firstValue-secondValue;
dollar = difference/100;
console.log(dollar);
//Create a Number visualization for that metric.
var myNumberVisualization = new Keen.Number(myMetric2, {
height: "300",
width: "600",
prefix:"$",
label: "Revenue"
});
//Draw the visualization in a div
myNumberVisualization.draw(document.getElementById("myDiv"),
{"result":dollar});
});
});
});
我想出如何采取一个Keen.Series和每个结果便士转换成美元格式(条带化API输出交易必须除以100才能找到美元值):
Keen.onChartsReady(function() {
// Create a Series
var mySeries = new Keen.Series("Stripe_Event", {
analysisType: "sum",
timeframe: "this_month",
interval: "daily",
targetProperty: "data.object.amount",
});
// Convert results from pennies to dollars
var resultsInDollars = {}
mySeries.getResponse(function(response){
result = response.result
$.each(result, function(index, object){
result[index]["value"] = object["value"]/100
});
resultsInDollars = {
result: result
}
// Line chart settings
var myLineChart = new Keen.LineChart(mySeries, {
height: 240,
width: 300,
xAxisLabelAngle:45
});
// Draw line chart
myLineChart.draw(document.getElementById("overview"),resultsInDollars);
});
});
在此先感谢。
这是一个共享Josh答案的解决方案。 https://gist.github.com/brentchow/9147264 –