[vtkusers] Activiz and vtkChartXY

Matthias Binninger MatthiasBinninger at gmx.de
Thu Feb 24 03:22:57 EST 2011


Thanks a lot!

 I got a little further with it, but not as far as I hoped ...

 renwin.GetInteractor().Disable();
 renwin.SetInteractor(view.GetInteractor());

 ... does the trick and makes it possible to use the chart inside the control, but only if

 * I don't use the load event handler but start the chart with a button afterwards
 * I don't do anything crazy like ...
 * * draging some other window over it and switch back to the chart
 * * or moving the chart window to my second screen.

 else the chart-only window appears and the original window gets messed up.

 My code:

private void Start()
 {
 const int NUM_POINTS = 100;
 const float INC = 7.5f / (NUM_POINTS - 1);

 vtkContextView view = vtkContextView.New();

 vtkRenderWindow renwin = renderWindowControl1.RenderWindow;

 renwin.RemoveRenderer(renwin.GetRenderers().GetFirstRenderer());
 renwin.AddRenderer(view.GetRenderer());

 renwin.GetInteractor().Disable();
 renwin.SetInteractor(view.GetInteractor());

 view.GetRenderer().SetBackground(1.0, 1.0, 1.0);

 vtkChartXY chart = vtkChartXY.New();
 chart.SetTitle("MyChart");
 chart.SetShowLegend(true);
 chart.GetAxis(0).SetTitle("Y");
 chart.GetAxis(1).SetTitle("X");

 view.GetScene().AddItem(chart);

 vtkTable table = vtkTable.New();

 vtkFloatArray arrX = vtkFloatArray.New();
 arrX.SetName("X");
 table.AddColumn(arrX);

 vtkFloatArray arrS = vtkFloatArray.New();
 arrS.SetName("Sine");
 table.AddColumn(arrS);

 vtkFloatArray arrC = vtkFloatArray.New();
 arrC.SetName("Cosine");
 table.AddColumn(arrC);

 table.SetNumberOfRows(NUM_POINTS);

 for (int i = 0; i < NUM_POINTS; i++)
 {
 arrX.SetValue(i, i * INC);
 arrS.SetValue(i, (float)Math.Sin(i * INC));
 arrC.SetValue(i, (float)Math.Cos(i * INC));
 }

 vtkPlotLine l_oPlot1 = (vtkPlotLine)chart.AddPlot((int)vtkChart.BAR_WrapperEnum.LINE);
 l_oPlot1.SetInput(table, 0, 1);
 l_oPlot1.SetColor(255, 0, 0, 255);

 vtkPlotLine l_oPlot2 = (vtkPlotLine)chart.AddPlot((int)vtkChart.BAR_WrapperEnum.LINE);
 l_oPlot2.SetInput(table, 0, 2);
 l_oPlot2.SetColor(0, 127, 127, 255);

 renwin.Render();
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110224/acb5e05b/attachment.htm>


More information about the vtkusers mailing list