[vtkusers] 2D Graph in VTK
Thomas Obenaus
thomaso at eas.iis.fraunhofer.de
Mon Sep 22 03:54:39 EDT 2008
Hi,
here is a short example written in Java. The function creates a vtkXYPlotActor which can directly added to the vtkRenderer. The input-data is a list of
vtkStructuredGrid.
public static vtkXYPlotActor makeXYPlot( ArrayList<vtkStructuredGrid> data,ArrayList<Color> colors,ArrayList<String> names,String xAxisName,String yAxisName,String plotTitle )
{
// actor representing an xy-plot
vtkXYPlotActor xyplot = new vtkXYPlotActor( );
for( int i=0;i<data.size( );i++ )
{
Color color = colors.get( i );
// adds the input-data for the plot (vtkDataSet e.g. vtkStructuredGrid)
// each input will be represented by one line in the plot
xyplot.AddInput( data.get( i ) );
// set the color for the entry (color of the line)
xyplot.GetLegendActor( ).SetEntryColor( i,( ( double )color.getRed( )/255.0 ),( ( double )color.getGreen( )/255.0 ),((double)color.getBlue()/255.0));
//set the name or identifier for the entry which should be displayed
xyplot.GetLegendActor( ).SetEntryString( i,names.get( i ));
}
// some global properties of the plot (position, title, etc...)
xyplot.GetPositionCoordinate( ).SetValue( 0.07,0.4,0.0 );
xyplot.GetPosition2Coordinate( ).SetValue( 0.9,0.33,0.0 );
xyplot.SetXValuesToValue( );
xyplot.SetNumberOfXLabels( 6 );
xyplot.SetTitle( plotTitle );
xyplot.SetXTitle( xAxisName );
xyplot.LegendOn ();
xyplot.SetYTitle( yAxisName );
xyplot.GetProperty( ).SetColor( 0,0,0 );
xyplot.GetProperty( ).SetLineWidth( 2 );
// the plot-font
vtkTextProperty tprop = xyplot.GetTitleTextProperty( );
tprop.SetColor( xyplot.GetProperty( ).GetColor( ) );
tprop.SetFontFamilyToArial( );
tprop.BoldOff( );
tprop.ItalicOn( );
xyplot.SetAxisTitleTextProperty( tprop );
xyplot.SetAxisLabelTextProperty( tprop );
return xyplot;
}
More information about the vtkusers
mailing list