# Using vtkChartXY with vtkMFCWindow

**URL:** https://discourse.vtk.org/t/using-vtkchartxy-with-vtkmfcwindow/2959
**Category:** Support
**Created:** [April 5, 2020, 5:09am UTC](https://discourse.vtk.org/t/using-vtkchartxy-with-vtkmfcwindow/2959 "2020-04-05T05:09:33Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![dwventer](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dwventer/32/1579_2.png) [@dwventer](https://discourse.vtk.org/u/dwventer)
#### Post date: [April 5, 2020, 5:09am UTC](https://discourse.vtk.org/t/using-vtkchartxy-with-vtkmfcwindow/2959/1 "2020-04-05T05:09:33Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![dwventer](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dwventer/32/1579_2.png) [@dwventer](https://discourse.vtk.org/u/dwventer)
#### Post date: [April 6, 2020, 4:24am UTC](https://discourse.vtk.org/t/using-vtkchartxy-with-vtkmfcwindow/2959/2 "2020-04-06T04:24:45Z")

</div>

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):

VTK\_MODULE\_INIT(vtkRenderingContextOpenGL2);

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?  
//this-\>pvtkMFCWindow-\>GetRenderWindow()-\>AddRenderer(pvtContextView-\>GetRenderer());  
this-\>pvtContextViewChart-\>SetRenderWindow(this-\>pvtkMFCWindow-\>GetRenderWindow());  
…
