尝试将Keen javascript可视化工具连接到两个数据集,在我尝试过的所有操作中都遇到错误。
尝试使用多重分析来获得响应,此方法有效,但未插入图表中。
https://keen.io/docs/api/#multi-analysis
还尝试运行单独的查询,并在敏锐的分析客户端上使用client.run
。每个查询分别运行良好,但是一起运行会在图表中产生与timeframe.start
有关的错误。
https://keen.io/docs/visualize/common-chart-examples/#area-step-chart-with-multiple-results
工具:
"keen-analysis": "^3.4.0",
"keen-dataviz": "^3.5.3",
"keen-tracking": "^4.3.1",
图表设置
const matchBreakdown = new keenDataviz({
container: "#match-breakdown",
type: "area-step",
title: "Match Breakdown (last 2 months)",
showLoadingSpinner: true
});
多重分析尝试:
client
.query("multi_analysis", {
event_collection: "kitchen.matches",
analyses: {
"total_matches": {
analysis_type: "count",
filters: [
{"operator":"eq","property_name":"environment","property_value":"production"}
]
},
"bad_matches": {
analysis_type: "count",
filters: [
{"operator":"eq","property_name":"environment","property_value":"production"},
{"operator":"eq","property_name":"match_count","property_value":0}
]
}
},
timezone: "US/Mountain",
group_by: ["date"],
order_by: ["date"],
timeframe: "this_60_days"
})
.then(res => {
matchBreakdown.render(res);
})
.catch(err => {
// Source data is missing a component at (0,1)!
matchBreakdown.message(err.message);
});
尝试多次查询:
const allMatches = client
.query("count", {
event_collection: "kitchen.matches",
filters: [{"operator":"eq","property_name":"environment","property_value":"production"}],
group_by: ["date"],
order_by: ["date"],
timezone: "US/Mountain",
timeframe: "this_2_months"
});
const badMatches = client
.query("count", {
event_collection: "kitchen.matches",
filters: [
{"operator":"eq","property_name":"environment","property_value":"production"},
{"operator":"eq","property_name":"match_count","property_value":0}
],
group_by: ["date"],
order_by: ["date"],
timezone: "US/Mountain",
timeframe: "this_2_months"
});
client
.run([allMatches, badMatches])
.then(res => {
matchBreakdown.render(res);
})
.catch(error => {
// Cannot read property 'start' of undefined
matchBreakdown.message(error.message);
});
请注意,这可行:
client.run([badMatches]).then(res => {
matchBreakdown.render(res);
});
// Or this
client.run([allMatches]).then(res => {
matchBreakdown.render(res);
});
这些示例没有提供有关如何格式化响应数据的更多信息,似乎应该可以正常工作。
答案 0 :(得分:2)
我正在检查您的问题,不幸的是filters
不能用于多重分析,而且您在运行少量查询group_by
时不能使用.run([allMatches, badMatches])
我基于以下示例准备了其他解决方案的示例:https://jsfiddle.net/a2fvmk1h/
您可以使用group_by
代替interval
来接收类似的结果。这是您的示例:https://jsfiddle.net/dariuszlacheta/h0x6mvan/14/
您在同一count
上使用相同查询event collection
的事实导致命名结果出现问题,因此您必须做一个技巧。您需要为结果至少更改一个“ analysis_type”,因为否则数据将被覆盖:res[1].query.analysis_type = 'games';
我无权访问您的数据,但我想这就是您的代码的样子:
const allMatches = client
.query("count", {
event_collection: "kitchen.matches",
filters: [
{
"operator":"eq",
"property_name":"environment",
"property_value":"production"
}
],
interval: "daily"
timezone: "US/Mountain",
timeframe: "this_2_months"
});
const badMatches = client
.query("count", {
event_collection: "kitchen.matches",
filters: [
{
"operator":"eq",
"property_name":"environment",
"property_value":"production"
},
{
"operator":"eq",
"property_name":"match_count",
"property_value":0
}
],
interval: "daily"
timezone: "US/Mountain",
timeframe: "this_2_months"
});
client
.run([allMatches, badMatches])
.then(res => {
res[1].query.analysis_type = 'badMatches';
matchBreakdown.render(res);
})
.catch(error => {
// Cannot read property 'start' of undefined
matchBreakdown.message(error.message);
});
在.run([])
中使用两个或多个相同查询时,我将尝试通过覆盖查询名称来解决此问题。