可视化多个数据集

Visualizing multiple datasets

正在尝试将 Keen javascript 可视化工具连接到两个数据集,但在我尝试过的所有操作中都遇到了错误。

尝试使用多重分析来获得响应,这有效但无法插入图表。

https://keen.io/docs/api/#multi-analysis

还尝试 运行ning 单独查询并在 keen 分析客户端上使用 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);
});

这些示例没有提供有关如何格式化响应数据的更多信息,它似乎应该可以正常工作。

我正在检查你的问题,不幸的是 filters 不适用于多重分析,你也不能使用 group_by 而 运行 几个查询 .run([allMatches, badMatches])

我基于此准备了其他解决方案的示例:https://jsfiddle.net/a2fvmk1h/

而不是 group_by 您可以使用 interval 来获得类似的结果。这是给你的例子:https://jsfiddle.net/dariuszlacheta/h0x6mvan/14/ 事实上,您在同一个 event collection 上使用相同的查询 count 会导致命名结果出现问题,因此您必须做一个技巧。您需要为结果更改至少一个 '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([])

中使用两个或多个相同查询时,我将尝试通过覆盖查询名称来解决此问题