cancel
Showing results for 
Search instead for 
Did you mean: 
OleksandrB
Sisense Team Member
Sisense Team Member

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

Screenshot_94.png
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.

Screenshot_95.png

Disclaimer: Please note, that this blog post contains one possible custom workaround solution for users with similar use cases. We cannot guarantee that the custom code solution described in this post will work in every scenario or with every Sisense software version. As such, we strongly advise users to test solutions in their own environment prior to deploying them to ensure that the solutions proffered function as desired in their environment. For the avoidance of doubt, the content of this blog post is provided to you “as-is” and without warranty of any kind, express, implied or otherwise, including without limitation any warranty of security and or fitness for a particular purpose. The workaround solution described in this post incorporates custom coding which is outside the Sisense product development environment and is therefore not covered by not covered by Sisense warranty and support services.

Rate this article:
Version history
Last update:
‎10-21-2024 10:39 AM
Updated by:
Contributors