I have this function inside a Component:
import React, { Component } from 'react';
import CanvasJSReact from '../../assets/canvasjs.react';
import _ from 'lodash';
class MyChart extends Component {
constructor() {
super();
this.generateDataPoints = this.generateDataPoints.bind(this);
}
generateDataPoints(noOfDps) {
var xVal = 1, yVal = 100;
var dps = [];
for(var i = 0; i < noOfDps; i++) {
yVal = yVal + Math.round(5 + Math.random() *(-5-5));
dps.push({x: xVal,y: yVal});
xVal++;
}
return dps;
}
render() {
var dataPoints = this.generateDataPoints(100);
console.log("dataPoints", dataPoints);
let yFirst = _.first(dataPoints);
let yLast = _.last(dataPoints);
let yMax = _.pick(dataPoints, 'y');
//console.log("Fisrt", yFirst, "Last:", yLast);
const {x: first, y: second } = dataPoints;
//let yMax = array.pick(dataPoints, 'y');
console.log("y", second);
}
return (...);
}
}
export default MyChart;
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
My dataSet is a plot on time (x), I want to calculate the minimum and maximum of y and generate a third property on those points, like this:
{ x: 40, y: 65 },
{ x: 50, y: 85, indexLabel: "highest"},
{ x: 60, y: 68 },
I´ve been trying to separate the array from dps in two to find min and max but it never works. I´m trying it with lodash library.
dataPointslook like.dataPoints, not how it's visually rendered.