[英]Plotting multiple lines on a Cube.js line graph
Imagine a simple line graph plotting a person count (y-axis) against a custom time value (x-axis), as such:想象一个简单的折线图,根据自定义时间值(x 轴)绘制人数(y 轴),如下所示:
Suppose you have another dimension, say specific groupings of people, how do you draw a separate line on this graph for each group?假设你有另一个维度,比如特定的人群,你如何在这个图表上为每个群体画一条单独的线?
You have to use the PivotConfig here an example I used in Angular (EDIT) Here is the Query您必须在此处使用 PivotConfig 一个我在 Angular 中使用的示例(编辑) 这是查询
Query = {
measures: ['Admissions.count'],
timeDimensions: [
{
dimension: 'Admissions.createdDate',
granularity: 'week',
dateRange: 'This quarter',
},
],
dimensions: ['Admissions.status'],
order: {
'Admissions.createdDate': 'asc',
},
}
(END EDIT) (结束编辑)
PivotConfig = {
x: ['Admissions.createdDate.day'],
y: ['Admissions.status', 'measures'],
fillMissingDates: true,
joinDateRange: false,
}
Code to extract data from resultset:从结果集中提取数据的代码:
let chartData = resultSet.series(this.PivotConfig).map(item => {
return {
label: item.title.split(',')[0], //title contains "ADMIS, COUNT"
data: item.series.map(({ value }) => value),
}
})
Result Object (not the one in the chart):结果 Object(不是图表中的那个):
[{
"label": "ADMIS",
"data": [2,1,0,0,0,0,0]
},{
"label": "SORTIE",
"data": [2,1,0,0,0,0,0]
}]
Here is what the output looks like!这是 output 的样子!
The chart renderer in the Developer Playground is meant to be quite simplistic; Developer Playground 中的图表渲染器非常简单。 I'd recommend creating a dashboard app or using one of our frontend integrations in an existing project to gain complete control over chart rendering.
我建议创建仪表板应用程序或在现有项目中使用我们的一个前端集成来完全控制图表呈现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.