Group values are on the column chart by day of the week.
Group values are on the column chart by day of the week.
We will check how to convert the usual Column chart with values and dates into a new chart with dates and values grouped by day of the week.
For example, we have such a chart
We want to see the common revenue for each day of the week (Monday, Tuesday, Wednesday, etc.).
Edit the widget by pressing the pencil icon, pressing the 3 dots in the upright corner of the widget, and choosing from the menu Edit Script. In a new window paste the following code
widget.on('beforeviewloaded', (scope, args) => {
const days = {
Monday: setInitialObject(),
Tuesday: setInitialObject(),
Wednesday: setInitialObject(),
Thursday: setInitialObject(),
Friday: setInitialObject(),
Saturday: setInitialObject(),
Sunday: setInitialObject()
};
args.options.xAxis.categories = Object.keys(days);
args.options.series.forEach((s) => {
let newMax = 0;
const currentSetup = {...{},...days};
s.data.forEach((point) => {
const currentDay = getDay(point.selectionData[0]);
currentSetup[currentDay].value += point.y;
if (newMax < currentSetup[currentDay].value) {
newMax = currentSetup[currentDay].value;
}
currentSetup[currentDay].selectionData.push(point.selectionData[0]);
if (!currentSetup[currentDay].color) {
currentSetup[currentDay].color = point.color;
}
})
s.data = Object.keys(currentSetup).map((point) => {
const { color, selectionData, value: y } = currentSetup[point];
return { y, selectionData, y };
})
args.options.yAxis[0].max = (!args.options.yAxis[0].max || args.options.yAxis[0].max < newMax) ? newMax : args.options.yAxis[0].max;
})
})
function setInitialObject() {
return {
value: 0,
selectionData: []
};
}
function getDay(date) {
const daysEnum = {
1: 'Monday',
2: 'Tuesday',
3: 'Wednesday',
4: 'Thursday',
5: 'Friday',
6: 'Saturday',
0: 'Sunday'
};
const dateIndex = date.getDay();
return daysEnum[dateIndex];
}
Press the 'Save' button. Apply the button to save the widget and refresh the page.
As a result, we see all days of the week and the sum of the revenues for them.
Disclaimer: This post outlines a potential custom workaround for specific use cases. The solution may not work in all scenarios or Sisense versions, so we strongly recommend testing it in your environment before deployment. The content is provided "as-is" without any warranty, including security or fitness for a particular purpose. Custom coding is involved, which falls outside Sisense's warranty and support.
Related Content:
https://docs.sisense.com/main/SisenseLinux/customizing-sisense-using-code.htm
https://academy.sisense.com/master-class-advanced-dashboards-with-plug-ins-and-scripts