[vtkusers] Cannot update vtkChartXY

Slaughter, Andrew E andrew.slaughter at inl.gov
Thu Oct 29 11:48:47 EDT 2015


I attempted to do the same thing you did (with Python VTK6.3), but it
wouldn't work for me either. The only way I was able to get it to work as
needed was to remove and re-create the line.

I came to this solution because of this:
http://vtk.1045678.n5.nabble.com/How-to-update-a-2d-plot-vtkChartXY-with-new-data-online-using-C-td5725677.html

However, it would be great is someone who was more familiar with VTK had a
better solution.

-Andrew

On Thu, Oct 29, 2015 at 9:42 AM, Elvis Chen <elvis.chen at gmail.com> wrote:

> hi all,
>
> I am trying to utilize vtkChartXY to plot a simple 2D curve but ran into
> some trouble, I seek your help.
>
> The 2D plot is a function of time and is been updated incrementally. I
> tried to follow the example at:
>
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Plotting/LinePlot
>
> to create an initial plot. As the data come in, I extended the vtkTable,
> and calls the renderer again, but only the initial table/plot was shown. A
> code demonstrating is the follow. Basically what I did was:
>
> - create a vtkTable with 3 data point, and plot it,
> - modify the vtkTable to include 1 more data point (4 total), and plot it
> again,
> - but the resulting plot only shows the original curve.
>
> Any help is very much appreciated,
>
> thanks,
>
>
>
> // arrX and arrY are vtkFloatArray
>
>   table->AddColumn( arrX );
>   table->AddColumn( arrY );
>
> // create a table of 3 data points
>   table->SetNumberOfRows( 3 );
>   table->SetValue( 0, 0, 0 );
>   table->SetValue( 0, 1, 0 );
>   table->SetValue( 1, 0, 1 );
>   table->SetValue( 1, 1, 1 );
>   table->SetValue( 2, 0, 2 );
>   table->SetValue( 2, 1, 3 );
>
> // render the chart
>   view->GetRenderer()->SetBackground( 1, 1, 1 );
>   view->GetScene()->AddItem( chart );
>   chart->SetShowLegend( true );
>   line = chart->AddPlot( vtkChart::LINE );
>   line->SetInput( table, 0, 1 );
>   line->SetColor( 1, 0, 0 );
>   line->SetWidth( 5.0 );
>
> // shows a plot of 3 data point
>   view->GetRenderer()->Render();
>
> // add a new point to the vtkTable
>   table->SetNumberOfRows( 4 );
>   table->SetValue( 0, 0, 0 );
>   table->SetValue( 0, 1, 0 );
>   table->SetValue( 1, 0, 1 );
>   table->SetValue( 1, 1, 1 );
>   table->SetValue( 2, 0, 2 );
>   table->SetValue( 2, 1, 3 );
>   table->SetValue( 3, 0, 5 );
>   table->SetValue( 3, 1, 5 );
>   table->Modified();
>   view->Modified();
>   line->Modified();
>
> // render it again, but still, only 3 data points were plot
>   view->GetRenderer()->Render();
>   view->GetInteractor()->Initialize();
>   view->GetInteractor()->Start();
>
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151029/f3401dd0/attachment.html>


More information about the vtkusers mailing list