I am trying to add a custom tooltip for each data point in line chart. The data that I am trying to pass to this line chart has the format:
The data that I receive from the API
[
{
old : "1",
current : "2",
oldtime : "1586217600000"
newtime: "1583625600000"
},
{
old : "2",
current : "3",
oldtime : "1596217600000"
newtime: "1583625600000"
},
{
old : "4",
current : "7",
oldtime : "1581217600000"
newtime: "1583185600000"
}
]
I was able to bring the two line graphs for old and current after transforming them into the following way
[
{
"name" : "old"
"data" : [1,2,4]
},
{
"name" : "current"
"data" : [2,3,7]
},
]
I am able to get the tooltip for these line graphs where it shows old and current value for each point. Now all I want is how to transform the api data to get the custom tooltip that includes old,current,oldtime,newtime values for each data point.
I am using the following function to transfrom the data
createLineChart = graphData => {
let data = [],old = [];
graphData.forEach(elem => {
old.push(elem.old);
current.push(elem.current);
});
data.push({ name: "BASELINE", data: old });
data.push({ name: "CURRENT", data: current });
return data;
};
Code sandbox: https://codesandbox.io/s/react-line-chart-n9g6o
Can someone help me here