可视化多个数据集

问题描述 投票:0回答:1

尝试将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
1个回答
2
投票

我正在检查你的问题和unfornatelly 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([])中使用两个或多个相同的查询时覆盖查询名称来解决此问题

© www.soinside.com 2019 - 2024. All rights reserved.