I'm trying to display financial data on a web app using the Chart.js library.
In my Node.js app, a user uploads a csv file. This file gets processed into a pandas dataframe by a flask rest api. The dataframe is saved on the flask server and is accessible via a get request. The get request returns a JSON object with fields Open, High, Low, Close, and Volume. These fields hold arrays.
I have a web socket (socket.io) established between my express server and a react component. My express server pings my flask api looking for the chart data. When the chart data is available (after uploading a file) the socket sends this data to the component. The client socket triggers a component method that creates the chart. A chart appears but has no data points displayed.
The component:
class Canvas extends Component {
constructor(props){
super(props);
this.state = {
data: false,
endpoint: 'http://localhost:4000'
}
this.establishSocket = this.establishSocket.bind(this);
this.makeChart = this.makeChart.bind(this);
}
componentDidMount() {
this.establishSocket();
}
establishSocket() {
const { endpoint } = this.state;
const socket = socketIOClient(endpoint);
socket.on("ohlcv_data", data => this.makeChart(data.Close));
}
makeChart(datapoints) {
this.setState({ data: datapoints })
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'line',
data: datapoints,
options: {
responsive: true,
maintainAspectRatio: false
}
});
console.log(myChart.data);
}
render() {
return (
<div id="chartContainer">
<canvas id="myChart"></canvas>
</div>
)
}
}
The charting code has been adapted from the Chart.js docs here:
https://www.chartjs.org/docs/latest/getting-started/usage.html
https://www.chartjs.org/docs/latest/charts/line.html
This is my app with the empty chart:

The console log at the bottom of the makeChart function displays the expected array. This is the output of that log:
My question is, what am I missing in this implementation in order to get the data to appear?

