echarts stacked resultset with a dimension
Hi @paveltiunov ,
In the official example for the vanilla js client https://codesandbox.io/s/131ymrj8vl?from-embed, I want to add the Orders.status as a dimension and then stack resulting Orders.count measure based on the status.
In this scenario, how should the xaxis data param be modified to take into account the new dimension Orders.status?
xAxis: {
data: resultSet.chartPivot().map(i => i.x)
},
I want to replicate the Orders by Status Over Time chart from the reach dashboard demo https://react-dashboard-demo.cube.dev/#/ in echarts.

Thanks, Siva
Hi, @devopsprosiva
You don't need to modify xAxis but you need to provide a pivotConfig to the chartPivot and series methods
const pivotConfig = {
x: ['Orders.createdAt.month'],
y: ['Orders.status', 'measures'],
};
and then you would be able to adjust the result for echarts
const echartsSeries = resultSet.series(pivotConfig).map((item) => {
return {
name: item.title,
type: 'bar',
stack: 'statusStack',
data: item.series.map(itemSeries => itemSeries.value)
}
})
Hi @vasilev-alex ,
Thanks for the suggestion. I made changes to the sandbox code as below, but I don't see any chart data? Could you please check and advise?
import echarts from "echarts";
import cubejs from "@cubejs-client/core";
// initialize cubejs instance with API Token and API URL
const cubejsApi = cubejs(
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.K9PiJkjegbhnw4Ca5pPlkTmZihoOm42w8bja9Qs2qJg",
{ apiUrl: "https://react-query-builder.herokuapp.com/cubejs-api/v1" }
);
// Load query for orders by created month in 2017 year
cubejsApi
.load({
measures: ["Orders.count"],
timeDimensions: [
{
dimension: "Orders.createdAt",
dateRange: ["2017-01-01", "2017-12-31"],
granularity: "month"
}
],
dimensions: ["Orders.status"]
})
.then(resultSet => {
// initialize echarts instance with prepared DOM
var myChart = echarts.init(document.getElementById("chart"));
const pivotConfig = {
x: ['Orders.createdAt.month'],
y: ['Orders.status', 'measures'],
};
const echartsSeries = resultSet.series(pivotConfig).map((item) => {
return {
name: item.title,
type: 'bar',
stack: 'statusStack',
data: item.series.map(itemSeries => itemSeries.value)
}
})
// draw chart
myChart.setOption({
xAxis: {
data: resultSet.chartPivot().map(i => i.x)
},
yAxis: {},
series: [
{
type: "bar",
data: echartsSeries.data
}
]
});
});
Please see the working example here https://codesandbox.io/s/cubejs-vanilla-javascript-client-0twnw
I also had to update @cubejs-client/core to the latest version as the one in the sandbox was too outdated.
@vasilev-alex Thanks for the new example.
Could you let me know how I can implement this in vuejs?
@Levhav Could you please take a look and let me know how to get this working in vuejs?
Could someone help me do this with React?