[vtkusers] difficulties with /vtkBarChartActor

Luke Hetrick lhetrick at nnu.edu
Thu Jul 19 15:35:10 EDT 2012


Using the following example as a starting point, I have been able to pass
in my type float arrays into the class /vtkBarChartActor. Using mostly bits
of code from the example mentioned, I can render the plot as well. My new
problem is that there is nothing plotted, it is just a blank chart with an
x and y axis. The y axis is scaled to fit the data in my arrays. I have
checked that by changing the values stored in a single array and passing
only that array into the /vtkBarChartActor so I know it is connecting
properly or at least that is is recognizing the range of data that is being
passed through it...I just am not sure how to make it place a bar for each
data point like the example shown does. Here is some relevant code to what
I am doing:


//this is inside some for loops and is getting filled with data, the
iterators of the for loops are i and n and are used to tell the array which
cell to put the data in
  vtkSmartPointer<vtkFloatArray> Angle =
      vtkSmartPointer<vtkFloatArray>::New();
  Angle->InsertValue( i + (5*n), acos( DotProduct /
                             ( EdgeLength->GetValue( i+(5*n )
                             * Magnitude_2) ) ) );

//the for loops have now been closed and the array is full of angles
ranging from 0.0 to about 3.0
 vtkSmartPointer<vtkDataObject> DataObject =
        vtkSmartPointer<vtkDataObject>::New();
      DataObject->GetFieldData()->AddArray ( Angle );

      vtkSmartPointer<vtkBarChartActor> Chart =
    vtkSmartPointer<vtkBarChartActor>::New();
      Chart->SetInput( DataObject );
      Chart->SetTitle( "Histogram" );
      Chart->GetPositionCoordinate()->SetValue(0.1,0.1,0.0);
      Chart->GetPosition2Coordinate()->SetValue(0.9,0.8,0.0);
      Chart->GetProperty()->SetColor(1,1,1);
      Chart->GetLegendActor()->SetNumberOfEntries(
DataObject->GetFieldData()->
             GetArray(0)->GetNumberOfTuples() );
      Chart->LegendVisibilityOn();
      Chart->LabelVisibilityOn();
      Chart->SetBarColor( 0,1.0,1.0,1.0 );
      Chart->SetYTitle( "Angle" );

      // Visualize the histogram(s)
      vtkSmartPointer<vtkRenderer> renderer =
        vtkSmartPointer<vtkRenderer>::New();
      renderer->AddActor( Chart );

      vtkSmartPointer<vtkRenderWindow> renderWindow =
        vtkSmartPointer<vtkRenderWindow>::New();
      renderWindow->AddRenderer( renderer );
      renderWindow->SetSize(640, 480);

      vtkSmartPointer<vtkRenderWindowInteractor> interactor =
        vtkSmartPointer<vtkRenderWindowInteractor>::New();
      interactor->SetRenderWindow( renderWindow );

      // Initialize the event loop and then start it
      interactor->Initialize();
      interactor->Start();



like I mentioned, this does not throw any errors or problems, it just
creates a blank plot that has a x axis that is not labeled and a y axis
that is labeled "Angle" and the y axis is always scaled to fit my float
array Angle. Any ideas as to why it is not plotting the data stored in the
array? And thank you for your help and time.

Luke H
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120719/2c25e009/attachment.htm>


More information about the vtkusers mailing list