1

Imagine a simple line graph plotting a person count (y-axis) against a custom time value (x-axis), as such:

cube.js line graph

Suppose you have another dimension, say specific groupings of people, how do you draw a separate line on this graph for each group?

Atticus
  • 147
  • 1
  • 9

2 Answers2

0

You have to use the PivotConfig here an example I used in Angular (EDIT) Here is the Query

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):

[{
  "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!

Here is what the output lookslike

Kaizendae
  • 853
  • 11
  • 24
-1

The chart renderer in the Developer Playground is meant to be quite simplistic; 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.

Hassan Khan
  • 766
  • 3
  • 9
  • 21
  • I’ve gone and created a dashboard app and had a read of the QueryBuilder and QueryRenderer. I saw that [this demo](https://external-rollups-demo.cube.dev/) has a graph with multiple lines on it but that seems to be because it uses a `timeDimension`. Instead, is it possible to have the x-axis one `dimension` and have separate lines for each of another `dimension`? – Atticus May 19 '21 at 18:14
  • I _think_ you should be able to manage that with the [`chartPivot()`](https://cube.dev/docs/@cubejs-client-core#result-set-chart-pivot) property on the `ResultSet` – Hassan Khan May 24 '21 at 01:03