[vtkusers] Cannot update vtkChartXY

Elvis Chen elvis.chen at gmail.com
Thu Oct 29 11:42:53 EDT 2015


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();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151029/41b81e63/attachment.html>


More information about the vtkusers mailing list