Menu

Series.setPoints(Point[]) doesn't update the chart (or does only once after rendering)

Joanna
2016-11-15
2021-09-28
  • Joanna

    Joanna - 2016-11-15

    I use a chart with one series which I need to update with different points on user's action (the chart is a histogram, and the user changes the step - influencing this way the number of bins). As a start I calculate the initial points, add them to the series - with series.setPoints(Point[])) - and add series to the chart - this works OK. When the user changes the parameters, I recalculate the points, use chart.getSeries(seriesId) to retrieve the series and on the retrieved series set the recalculated points - again with series.setPoints(Point[]). This works fine - the plot updates correctly, but if I do it only once (this is strange that it works once and not again), but if I do it for the second time the plot doesn't update.
    If I do the same by removing points one by one (with series.removePoint(Point)) and then add the new points one by one (with series.addPoint(Point)) everything works fine every time. However, I prefer the setPoints method as it works more efficiently.

     
  • Shawn Quinn

    Shawn Quinn - 2016-11-15

    Hmm, that does sound odd. We use setPoints() regularly here for most of the charts in GWT applications that support dynamic updates, and haven't noticed this kind of an issue. Can you boil this does to a smaller code example/use case that you can post here so that we can take a closer look to see what may be going wrong?

     
    • Joanna

      Joanna - 2017-04-25

      Sorry for the late reply, but I haven't noticed your answer until today.
      Taking the relevant part from my code, it looks like the example below:
      This works:

      Series histogramSeries = this.getSeries(histogramSeriesID);
      for (Point p : histogramSeries.getPoints()) {
              histogramSeries.removePoint(p, false, false);
      }
      for (Point p : points) {
              histogramSeries.addPoint(p, false, false, false);
      }
      histogramSeries.update(histogramSeries);
      

      This doesn't work (works only once):

      Series histogramSeries = this.getSeries(histogramSeriesID);
      histogramSeries.setPoints(points);
      histogramSeries.update(histogramSeries);
      

      points is an array of Point objects (Point[]).

       

      Last edit: Joanna 2017-04-25
  • Shawn Quinn

    Shawn Quinn - 2017-04-25

    I think the call to "update()" is what may be causing the problem there. Try just using "histogramSeries.setPoints()" by itself, which will internally automatically apply and draw the new points to the series in the chart. (Note that are also overloaded versions of "setPoints()" available that will allow you to control when the chart is redrawn if you're updating many series at once.)

    The "Series.update()" method is a newer method that is intended for a different use case (specifically for updating the render configuration options for the series after the series has been rendered). We'll get a ticket logged to check into ensuring that use of the "update" method is compatible with use of the "setPoints" method, but for your use case I think all you'll need is the "setPoints" method anyways.

    Let us know if that clears up your use case!

     
  • Joanna

    Joanna - 2017-04-27

    It seems that without the update() method it works.
    Thanks,

     

    Last edit: Joanna 2017-04-27
  • Joanna

    Joanna - 2017-06-12

    Hi,
    I'm, coming back to this issue, as it seems that in another plot I do need the update() method. I set points as before (series.setPoints(Point [])) and would like to additionally change the series name - which should be updated in the legend. Without the update() method, the legend displays old series name, and with update(), the plot itself doesn't update...

     
  • Joanna

    Joanna - 2017-06-14

    I also noticed that after invoking series.setPoints(Point[]) in this way (when it is called second or later time), series.getPoints() returns an empty array.

     
  • Ram

    Ram - 2021-09-28

    I know I am asking this very late, but by any chance did you get the solution or work around?

     

Log in to post a comment.