【发布时间】:2019-04-02 21:06:09
【问题描述】:
尝试将 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);
});
这些示例没有提供有关如何格式化响应数据的更多信息,似乎它应该可以工作。
【问题讨论】:
标签: javascript keen-io