Using vtkChartXY with vtkMFCWindow

So I found plenty of examples where I can plot a chart using something like the vtkChartXY and vtkContextView object. Something like “pvtContextViewChart->GetScene()->AddItem(pvtChart);” is needed.

Can something please then tell me how do I add the Chart object to the vtkMFCWindow object?

I manage to solve my problem. I forgot to initiate vtkRenderingContextOpenGL2 which caused my GetDevice() to return null.

In case someone else is also struggling. Add the following to your main stdafx.h or pch.h (or some other appropriate place):


Remember to add the necessary libraries if you have unresolved externals (e.g. vtkRenderingContextOpenGL2-8.2.lib).

Then somewhere in your code:

this->pvtContextView= vtkSmartPointer::New();
//Either one of the following 2 lines work. Can someone say witch one is more appropriate?