# Plotting y vapues on chartxy

**URL:** <https://discourse.vtk.org/t/plotting-y-vapues-on-chartxy/13328>\
**Category:** Development\
**Created:** [February 17, 2024, 1:21am UTC](https://discourse.vtk.org/t/plotting-y-vapues-on-chartxy/13328 "2024-02-17T01:21:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafael\_Scatena](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rafael_scatena/32/7820_2.png) [@Rafael\_Scatena](https://discourse.vtk.org/u/Rafael_Scatena)\
**Post date:** [February 17, 2024, 1:21am UTC](https://discourse.vtk.org/t/plotting-y-vapues-on-chartxy/13328/1 "2024-02-17T01:21:14Z")

</div>

Hi,

Is it possible to plot the y values of each point in chartxy?

Thank you

---

<div class="post-metadata">

**Author:** ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)\
**Post date:** [February 18, 2024, 9:15pm UTC](https://discourse.vtk.org/t/plotting-y-vapues-on-chartxy/13328/2 "2024-02-18T21:15:22Z")

</div>

Hello,

Yes.

best,

PC

---

<div class="post-metadata">

**Author:** ![Rafael\_Scatena](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rafael_scatena/32/7820_2.png) [@Rafael\_Scatena](https://discourse.vtk.org/u/Rafael_Scatena)\
**Post date:** [February 21, 2024, 8:53pm UTC](https://discourse.vtk.org/t/plotting-y-vapues-on-chartxy/13328/3 "2024-02-21T20:53:20Z")

</div>

I tryed this but it dind’t work:

```
    // Add multiple line plots, setting the colors etc.
    vtkNew<vtkChartXY> chart;
    view->GetScene()->AddItem(chart);
    vtkPlot* line = chart->AddPlot(vtkChart::LINE);
    line->SetInputData(table, 0, 1);
    auto lineColor = colors->HTMLColorToRGBA("Lime").GetData();
    line->SetColor(lineColor[0], lineColor[1], lineColor[2], lineColor[3]);
    line->SetWidth(3.0);
    
    std::vector<vtkSmartPointer<vtkActor>> actors;
std::vector<vtkSmartPointer<vtkTextMapper>> textMappers;
std::vector<vtkSmartPointer<vtkActor2D>> textActors;
  vtkNew<vtkTextProperty> textProperty;
  textProperty->SetFontSize(16);
  textProperty->SetJustificationToCentered();

    
    // Iterate over the table and add text annotations for each point
for (vtkIdType i = 0; i < table->GetNumberOfRows(); ++i) {
    // Get x and y values of the point
    double xValue = table->GetValue(i, 0).ToDouble();
    double yValue = table->GetValue(i, 1).ToDouble();

    // Create a text annotation for the point's value
    // Create a text annotation for the point's value
    textMappers.push_back(vtkSmartPointer<vtkTextMapper>::New());
    textMappers[i]->SetInput(std::to_string(yValue).c_str());
    textMappers[i]->SetTextProperty(textProperty);

    textActors.push_back(vtkSmartPointer<vtkActor2D>::New());
    textActors[i]->SetMapper(textMappers[i]);
	     textActors[i]->SetPosition(xValue, yValue);
     
     view->GetRenderer()->AddActor(textActors[i]);}

```

---

<div class="post-metadata">

**Author:** ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)\
**Post date:** [February 21, 2024, 10:27pm UTC](https://discourse.vtk.org/t/plotting-y-vapues-on-chartxy/13328/4 "2024-02-21T22:27:55Z")

</div>

What happens?

---

<div class="post-metadata">

**Author:** ![Rafael\_Scatena](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rafael_scatena/32/7820_2.png) [@Rafael\_Scatena](https://discourse.vtk.org/u/Rafael_Scatena)\
**Post date:** [February 22, 2024, 12:08am UTC](https://discourse.vtk.org/t/plotting-y-vapues-on-chartxy/13328/5 "2024-02-22T00:08:39Z")

</div>

It plots without the points

![Cell Tree Locator Timing](https://discourse.vtk.org/uploads/default/original/2X/3/37ba5a7331c7dcd30299c88ad0f1fe4c0ad7c34e.png)

---

<div class="post-metadata">

**Author:** ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)\
**Post date:** [February 22, 2024, 3:11pm UTC](https://discourse.vtk.org/t/plotting-y-vapues-on-chartxy/13328/6 "2024-02-22T15:11:06Z")

</div>

Then you need to add a second plot to the chart with points instead of connected lines:

```cpp
   vtkPlot* points = chart->AddPlot(vtkChart::POINTS);
   points->SetInputData(table, 0, 1);
   dynamic_cast<vtkPlotPoints*>(points)->SetMarkerStyle(vtkPlotPoints::DIAMOND);
   points->SetColor(lineColor[0], lineColor[1], lineColor[2], lineColor[3]);

```

This sets the same XY data you assigned to the `lines` plot so you have diamond-shaped bullets along green line with the same color.

Here, this is a more complete example of how to plot XY values as points: [https://examples.vtk.org/site/Cxx/Plotting/ChartMatrix/](https://examples.vtk.org/site/Cxx/Plotting/ChartMatrix/)

---

<div class="post-metadata">

**Author:** ![Rafael\_Scatena](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rafael_scatena/32/7820_2.png) [@Rafael\_Scatena](https://discourse.vtk.org/u/Rafael_Scatena)\
**Post date:** [February 22, 2024, 5:37pm UTC](https://discourse.vtk.org/t/plotting-y-vapues-on-chartxy/13328/7 "2024-02-22T17:37:11Z")

</div>

I want something like this:  
 ![image](https://discourse.vtk.org/uploads/default/original/2X/8/865df169fbf07f0745a7860b40b98b1e569e7444.png)

---

<div class="post-metadata">

**Author:** ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)\
**Post date:** [February 22, 2024, 6:10pm UTC](https://discourse.vtk.org/t/plotting-y-vapues-on-chartxy/13328/8 "2024-02-22T18:10:15Z")

</div>

I’ve told exactly what you need to do to achieve that.
