Hi team, I have requirement where I need multiple category axis points. I’ve attached the screenshot for reference.
image.png (2.2 KB)
I’m adding both the category axis data and values axis data using the getChartDataWorkbook method. The value axis data is getting loaded properly but the category axis data is not getting displayed properly in the chart output.
At first it shows only one category axis data point like the screenshot attached below.
image.png (14.6 KB)
Once I open the chart work book using the edit data options both the category axis data gets displayed properly.
image.png (36.9 KB)
I’m using the below code to prepare the chart.
"data": {
"categories": [
[
"2021-new",
"2022-new",
"2023-new",
"2024-new"
],
[
"Warehouse-new",
"Warehouse-new",
"Warehouse-new",
"Warehouse-new"
]
],
"series": [
{
"name": "Average of renewable rate",
"values": [
0.18,
0.70,
0.50,
0.30
]
},
{
"name": "Average of expiring rate",
"values": [
0.2,
1,
0.5,
0.75
]
}
]
},
"config": {
"chartTitle": "Test Title",
"multipleCategory": true
}
const chartDataObject = placeHolder.data as IChartData;
const chartData = shape.getChartData();
const chartCategory = chartData.getCategories();
const fact = chartData.getChartDataWorkbook();
chartDataObject.categories.forEach((category: any, categoryIndex: number) => {
category.forEach((ele: any, elementIndex: number) => {
chartData.getCategories().add(fact.getCell(0, elementIndex + 1, categoryIndex, ele));
})
});
const chartDataObject = placeHolder.data as IChartData;
const chartData = shape.getChartData();
const chartSeries = chartData.getSeries();
const fact = chartData.getChartDataWorkbook();
const columnType = shape.getType();
const columnShift = placeHolder?.config?.multipleCategory ? chartDataObject.categories.length - 1 : 0;
chartDataObject.series.forEach((ele, seriesIndex) => {
chartSeries.add(fact.getCell(0, 0, seriesIndex + 1 + columnShift, ele.name), columnType);
const series = chartSeries.get_Item(seriesIndex);
series.setInvertIfNegative(false);
ele.values.forEach((value, valueIndex) => {
const dataPoint = series
.getDataPoints()
.addDataPointForBarSeries(
fact.getCell(0, valueIndex + 1, seriesIndex + 1 + columnShift, value ? value : 0)
);
});
});