# Iam getting a error regarding an exception in the below code . what is the problem .Iam unable to get that one

**URL:** https://discourse.vtk.org/t/iam-getting-a-error-regarding-an-exception-in-the-below-code-what-is-the-problem-iam-unable-to-get-that-one/12804
**Category:** Support
**Created:** [November 29, 2023, 6:43am UTC](https://discourse.vtk.org/t/iam-getting-a-error-regarding-an-exception-in-the-below-code-what-is-the-problem-iam-unable-to-get-that-one/12804 "2023-11-29T06:43:25Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Nattu\_Natasha](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nattu_natasha/32/8075_2.png) [@Nattu\_Natasha](https://discourse.vtk.org/u/Nattu_Natasha)
#### Post date: [November 29, 2023, 6:43am UTC](https://discourse.vtk.org/t/iam-getting-a-error-regarding-an-exception-in-the-below-code-what-is-the-problem-iam-unable-to-get-that-one/12804/1 "2023-11-29T06:43:25Z")

</div>

#include \<vtkSmartPointer.h\>  
#include \<vtkChartXY.h\>  
#include \<vtkPlot.h\>  
#include \<vtkFloatArray.h\>  
#include \<vtkTable.h\>  
#include \<vtkContextView.h\>  
#include \<vtkRenderWindow.h\>  
#include \<vtkRenderWindowInteractor.h\>  
#include \<vtkAxis.h\>

#include   
#include   
#include

#include \<vtkAutoInit.h\>  
VTK\_MODULE\_INIT(vtkRenderingOpenGL2)  
VTK\_MODULE\_INIT(vtkRenderingFreeType)

int main()  
{  
// Read numbers from a text file and store them in vectors  
std::ifstream file(“C:/Users/durga.pp/Downloads/tst.txt”);  
if (!file.is\_open())  
{  
std::cerr \<\< “Failed to open the file!” \<\< std::endl;  
return EXIT\_FAILURE;  
}

```
std::vector<double> data;
double value;
while (file >> value)
{
    data.push_back(value);
}
file.close();

// Create a VTK table and add a column to store the data
vtkSmartPointer<vtkTable> table = vtkSmartPointer<vtkTable>::New();
vtkSmartPointer<vtkFloatArray> dataArray = vtkSmartPointer<vtkFloatArray>::New();
dataArray->SetName("Data");
for (size_t i = 0; i < data.size(); ++i)
{
    dataArray->InsertNextValue(data[i]);
}
table->AddColumn(dataArray);

// Create a VTK chart and add a plot with the data
vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();
vtkPlot* points = chart->AddPlot(vtkChart::POINTS);
points->SetInputData(table, 0, 0);

// Set up axes
vtkAxis* xAxis = chart->GetAxis(vtkAxis::BOTTOM);
xAxis->SetTitle("X-axis");

vtkAxis* yAxis = chart->GetAxis(vtkAxis::LEFT);
yAxis->SetTitle("Y-axis");

// Create a VTK context view and render window
vtkSmartPointer<vtkContextView> view = vtkSmartPointer<vtkContextView>::New();
view->GetRenderWindow()->SetSize(800, 600);
view->GetScene()->AddItem(chart);

// Set up interactor and start rendering
vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow(view->GetRenderWindow());
view->GetInteractor()->SetInteractorStyle(nullptr);
view->GetRenderWindow()->Render();
view->GetInteractor()->Start();

return EXIT_SUCCESS;

```

}
