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?

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Merci beaucoup. Would it be possible to include the query as well?
I added the query, Hope it helps!
-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.

2 Comments

I’ve gone and created a dashboard app and had a read of the QueryBuilder and QueryRenderer. I saw that this demo 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?
I think you should be able to manage that with the chartPivot() property on the ResultSet

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.