I want to create a scatter chart where the x value is the calculated median value from different SharePoint List fields. The x-axis is fixed. I have ratings from different persons for different questions/ratings. The number can be from 1...5. I need at first to filter after the field and then I get all the field values where I need the median value.
I get an array (_items) and from this array I want to have the median value and give it back to x: .If the array is even I need the number in the middle of the array. Otherwise I need to find the two numbers in the middle and divide it by 2 and give it back. The value should saved in the x:
I don't know how I can calculate the different cases. I help you can help me.
This is my code so far:
React.useEffect(() => {
if(!props.user) return;
props.spService.ReadValuesForSpecificMentee("Test-list",
props.user.person.EMail)
.then((_items) => [
{
x: _items.map((item)=> parseInt(item.M3Rating)).sort((a,b)=> a - b).{if array is even -> find middle number and give it back else array is uneven then finde the last number in the first part of the array and find the first number in second part. then divid /2 and give the number back}
,
y: 1
},
{
x: //same calculation for M2,
y: 2
},
{
x: //same calculation for M3,
y: 3
}
])
.then((_data) => { create Chart}