gpt4 book ai didi

javascript - Keen.io 如何使用 savedQueries() 绘制图表

转载 作者:行者123 更新时间:2023-11-29 19:03:41 25 4
gpt4 key购买 nike

我尝试使用 savedQueries 绘制图形但没有成功。 savedQueries 仅用于 Keen 中的 CRUD 查询还是它实际上也可以用于图表??从代码中删除了 key ,对于给您带来的不便,我们深表歉意。

var client = new Keen({
projectId: keen.project,
writeKey: keen.writeKey,
readKey: keen.readKey,
masterKey: keen.masterKey
});
var savedQueries = client.savedQueries();
savedQueries.get("monthly-active-users", function(err, response) {
if (err) {
console.log(err);
}
console.log(response);
var chart1 = new Keen.Dataviz()
.el(document.getElementById('chart'))
.chartType("area")
.colors(["#6ab975"])
.title("Monthly Active Users")
.prepare();

chart1
.data(response)
.render();

});

保存查询的响应对象

{
"refresh_rate": 0,
"user_last_modified_date": "2017-06-09T18:51:59.676000+00:00",
"last_modified_date": "2017-06-09T18:51:59.676000+00:00",
"query_name": "monthly-active-users",
"urls": {
"cached_query_url": "/3.0/projects/58f6fb8a90b3659264951b8d/queries/saved/monthly-active-users",
"cached_query_results_url": "/3.0/projects/58f6fb8a90b3659264951b8d/queries/saved/monthly-active-users/result"
},
"created_date": "2017-04-25T23:52:45.685000+00:00",
"query": {
"filters": [
{
"operator": "ne",
"property_name": "user_id",
"property_value": "guest"
},
{
"operator": "not_contains",
"property_name": "fromState",
"property_value": "app"
},
{
"operator": "not_contains",
"property_name": "user_email",
"property_value": "@giblib.com"
},
{
"operator": "not_contains",
"property_name": "fromState",
"property_value": "app.auth_postregister"
}
],
"analysis_type": "count_unique",
"timezone": "US/Pacific",
"group_by": null,
"force_exact": null,
"timeframe": "this_2_months",
"target_property": "user_id",
"interval": "monthly",
"event_collection": "user-page-access"
},
"run_information": null,
"metadata": {
"visualization": {
"chart_type": "areachart"
},
"display_name": "Monthly Active Users"
}
}

最佳答案

我注意到您没有包含 Keen.ready() 函数。此外,我建议使用 client.run 而不是 client.get,因为它会运行查询并获取结果。

我继续创建了一个 JSFiddle 示例:https://jsfiddle.net/pn14bs0L/2/

Keen.ready(function() {

client.run("test-saved-query", function(err, response) {
if (err) {
// there was an error
} else {
var chart1 = new Keen.Dataviz()
.el(document.getElementById('my_chart'))
.chartType("areachart")
.colors(["#6ab975"])
.title("Monthly Active Users")
.prepare();

chart1
.data(response)
.render();
}
});

});

您可以在 JSFiddle 中看到它使用一些测试数据。

注意:我假设您在这里使用的是 keen-js 而不是 keen-dataviz.js。

关于javascript - Keen.io 如何使用 savedQueries() 绘制图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44636266/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com