Skip to content

Commit 6144a86

Browse files
authored
feat: Return key in the resultSet.series alongside title (#291)
1 parent fd39c95 commit 6144a86

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

packages/cubejs-client-core/src/ResultSet.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,41 @@ class ResultSet {
3535
this.loadResponse = loadResponse;
3636
}
3737

38+
/**
39+
* Returns an array of series with key, title and series data.
40+
*
41+
* ```js
42+
* // For query
43+
* {
44+
* measures: ['Stories.count'],
45+
* timeDimensions: [{
46+
* dimension: 'Stories.time',
47+
* dateRange: ['2015-01-01', '2015-12-31'],
48+
* granularity: 'month'
49+
* }]
50+
* }
51+
*
52+
* // ResultSet.series() will return
53+
* [
54+
* {
55+
* "key":"Stories.count",
56+
* "title": "Stories Count",
57+
* "series": [
58+
* { "x":"2015-01-01T00:00:00", "value": 27120 },
59+
* { "x":"2015-02-01T00:00:00", "value": 25861 },
60+
* { "x": "2015-03-01T00:00:00", "value": 29661 },
61+
* //...
62+
* ]
63+
* }
64+
* ]
65+
* ```
66+
* @param pivotConfig
67+
* @returns {Array}
68+
*/
3869
series(pivotConfig) {
3970
return this.seriesNames(pivotConfig).map(({ title, key }) => ({
4071
title,
72+
key,
4173
series: this.chartPivot(pivotConfig).map(({ category, x, ...obj }) => ({ value: obj[key], category, x }))
4274
}));
4375
}

0 commit comments

Comments
 (0)