GithubHelp home page GithubHelp logo

Comments (10)

ppotaczek avatar ppotaczek commented on June 27, 2024 1

Yes, Highcharts mutate source data array for performance. You can check this thread: highcharts/highcharts#4259 for more information.

from highcharts-react.

KacperMadej avatar KacperMadej commented on June 27, 2024

Hi @ritou11

Currently only chart.update is used, so if you require an advanced solution then you could try using Highcharts without the wrapper and call API functions that will work best for your chart performance.

Internal note:
Possible enhancement - enable series.addPoint function call through the wrapper without triggering chart.update or maybe something more general, like marking the change as handled when a custom code handles it.

from highcharts-react.

ldelossa avatar ldelossa commented on June 27, 2024

@KacperMadej are we able to access the chart directly via reft? Like the example here:
https://github.com/kirjs/react-highcharts

from highcharts-react.

ppotaczek avatar ppotaczek commented on June 27, 2024

Hi @ldelossa,

Yes, you can access directly the chart by refs, for example in this way:

class Chart extends React.Component {
  constructor(props) {
    super(props);
    this.chartComponent = React.createRef();

    this.state = {
      options: {
        series: [
          {
            data: [1, 2, 3]
          }
        ]
      }
    };
  }

  componentDidMount() {
    const chart = this.chartComponent.current.chart;
    // ...
  }

  render() {
    return (
      <HighchartsReact
        constructorType={"chart"}
        ref={this.chartComponent}
        highcharts={Highcharts}
        options={this.state.options}
      />
    );
  }
}

Best regards!

from highcharts-react.

ldelossa avatar ldelossa commented on June 27, 2024

If I wanted to extend the above concept to live updating data, do you have any recommendation? Currently I’m pulling data from a websocket and I’d like to add a point or multiple points to the existing array in an efficiently manner

from highcharts-react.

ppotaczek avatar ppotaczek commented on June 27, 2024

@ldelossa,

It depends on the amount of data and the interval. You can test the following solutions and find out which one will be best for you:

We try to keep this repository only for bugs, so in the future please contact Highcharts suport for this type of questions: https://www.highcharts.com/blog/support/

Best regards!

from highcharts-react.

LucidityDesign avatar LucidityDesign commented on June 27, 2024

I'm using Highstock and have something like this as dataset:

[
  [timestamp, 1.2],
  [timestamp + 1s, 1.4],
  [timestamp + 2s, 0.9],
...
]

If I use state or setState the limits and range the user has selected gets overridden due to the re-renderings.

If I use addPoint the navigator messes up my data.
I have one series and add data by calling:

shouldComponentUpdate (nextProps) {
  chart.series[0].addPoint(nextProps.values[nextProps.values.length - 1], true, true)`
  return false
}

After that I can see following output:

console.log(chart.series[0].data) // my data
=>
52: C {series: v, x: 1565355010863, y: 0, options: {…}, isNull: false, …}
53: C {series: v, x: 1565355011863, y: 0, options: {…}, isNull: false, …}
54: C {series: v, x: 1565355012863, y: 0, options: {…}, isNull: false, …}
55: C {series: v, x: 1565355013863, y: 46.16563087189379, options: {…}, isNull: false, …}
56: C {series: v, x: 1565355013863, y: 46.16563087189379, options: {…}, isNull: false, …}
57: C {series: v, x: 1565355015907, y: 50.51810410147327, options: {…}, isNull: false, …}
58: C {series: v, x: 1565355017853, y: 45.926992636929334, options: {…}, isNull: false, …}
59: C {series: v, x: 1565355019811, y: 45.545298897828026, options: {…}, isNull: false, …}
60: C {series: v, x: 1565355021846, y: 41.76886760720148, options: {…}, isNull: false, …}
console.log(chart.series[1].data) // data of navigator (?)
=>
52: C {series: v, x: 1565355010863, y: 0, options: {…}, isNull: false, …}
53: C {series: v, x: 1565355011863, y: 0, options: {…}, isNull: false, …}
54: C {series: v, x: 1565355012863, y: 0, options: {…}, isNull: false, …}
55: C {series: v, x: 1565355013863, y: 46.16563087189379, options: {…}, isNull: false, …}
56: C {series: v, x: 1565355013863, y: 46.16563087189379, options: {…}, isNull: false, …}
57: C {series: v, x: 1565355015907, y: 50.51810410147327, options: {…}, isNull: false, …}
58: C {series: v, x: 1565355017853, y: 45.926992636929334, options: {…}, isNull: false, …}
59: C {series: v, x: 1565355019811, y: 45.545298897828026, options: {…}, isNull: false, …}
60: C {series: v, x: 1565355021846, y: 41.76886760720148, options: {…}, isNull: false, …}
61: C {series: v, x: 1565355015907, y: 50.51810410147327, options: {…}, isNull: false, …}
62: C {series: v, x: 1565355017853, y: 45.926992636929334, options: {…}, isNull: false, …}
63: C {series: v, x: 1565355019811, y: 45.545298897828026, options: {…}, isNull: false, …}
64: C {series: v, x: 1565355021846, y: 41.76886760720148, options: ...

As you can see, series[0] is sorted correctly while series[1][60] has a higher timestamp than the following values.

from highcharts-react.

ppotaczek avatar ppotaczek commented on June 27, 2024

Hi @LucidityDesign,

That issue is probably not related with highcharts-react-official wrapper. Could you reproduce it without the wrapper in some online code editor?

You can start from: http://jsfiddle.net/BlackLabel/z394cktd/

Best regards!

from highcharts-react.

LucidityDesign avatar LucidityDesign commented on June 27, 2024

Hi,
thanks, I can reproduce it with setData: http://jsfiddle.net/obpuj0wy/

It seems like Highcharts is modifying my data array. If I pass a clone of the array ([...data]) it works as expected

from highcharts-react.

ppotaczek avatar ppotaczek commented on June 27, 2024

The best way to add a new point is to call addPoint method directly on the chart. Our wrapper architecture does not provide for any other possibility.

from highcharts-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.