question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Candlestick chart does not redraw at every state change

See original GitHub issue

I have a Chart component which gets chart data from two sources: The first provides historic candlestick data every minute. The second provides real time data of the current candlestick. Both update the series object via setState.

The issue is, that only the first source updates the chart.

I expect that after the second source sends a current candle stick data and i update the state, the last candlestick updates on the chart, but it doesnt. It doesn’t move. Although the render is triggered after both updates (from first and second source), which i can seek in the console output. Also I can see in the log that this.state.series has exactly the same format after both kind of updates.

Here is the code of my chart component:

`import React from “react”; import Chart from “react-apexcharts”; import moment from “moment”;

export default class ChartComponent extends React.Component { constructor(props) { super(props);

  this.state = {
      series: [{data:[]}],
      options: {chart: {id: "basic-bar"}}
    }
}

componentDidMount() {     
  this.startEventSource();
}

startEventSource() {
  this.eventSource = new EventSource(`http://localhost:9000/candleStream`);
  this.eventSource.onmessage = e => this.updateChart(JSON.parse(e.data), "Minute");

  this.eventSource2 = new EventSource(`http://localhost:9000/priceStream`);
  this.eventSource2.onmessage = e => this.updatePrice(JSON.parse(e.data))         
}        

updatePrice = (newCandleData) => {
  
  var candleData = newCandleData.split(";");
  let momentWithoutSeconds = moment(parseInt(candleData[4])).seconds(0).milliseconds(0).valueOf();      
  let candle = [momentWithoutSeconds, parseFloat(candleData[0]), parseFloat(candleData[1]), parseFloat(candleData[2]), parseFloat(candleData[3]) ]    
  let newCandleList = this.state.series[0].data;

  if(newCandleList.filter(c => c[0] == momentWithoutSeconds).length == 0) {        
    newCandleList.push(candle);        

  } else {
    newCandleList[newCandleList.length - 1] = candle;
  }    

  this.updateChart([{data:newCandleList}], "Price");      
}    

updateChart = (data, source) => {                 
  this.setState({series: data},  console.log(source, this.state.series));
}  

render() {
  console.log("render triggered!")
  return (
    <div className="app">
      <div className="row">
        <div className="mixed-chart">
          <Chart
            options={this.state.options}
            series={this.state.series}
            type="candlestick"
            width="1000"
          />
        </div>
      </div>
    </div>
  );  
}

}`

And here an example console output where the structure of series is visible: image

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

1reaction
yohainnncommented, Aug 9, 2020

same problem here

1reaction
flolegecommented, Apr 1, 2020

EDIT: The chart DOES update while I am/keep resizing the browser window.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ApexChart Candlestick does not redraw at every state change
The issue is, that only the first source updates the chart. I expect that after the second source sends a current candle stick...
Read more >
ApexChart Candlestick does not redraw at every state change ...
Coding example for the question ApexChart Candlestick does not redraw at every state change-Reactjs.
Read more >
Candlestick Math - A New Way Of Using Candlesticks - YouTube
When two single candle lines are combined, the meaning on the chart can become much more significant. You'll get an even sharper view...
Read more >
Candlestick Patterns For Beginners (The Ultimate Guide)
In this training, you'll learn:1. The truth about candlestick patterns that nobody tells you2. How to read and understand any candlestick ...
Read more >
Candlestick Chart vs Line Chart - YouTube
Candlestick chart vs line chart is explained in this video to show the differences between these two common price charts. First, line chart ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found