# Can't change axis labels in vtkChartXYZ?

**URL:** https://discourse.vtk.org/t/cant-change-axis-labels-in-vtkchartxyz/3394
**Category:** Support
**Created:** [May 25, 2020, 5:24pm UTC](https://discourse.vtk.org/t/cant-change-axis-labels-in-vtkchartxyz/3394 "2020-05-25T17:24:49Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![mdaley](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mdaley/32/1872_2.png) [@mdaley](https://discourse.vtk.org/u/mdaley)
#### Post date: [May 25, 2020, 5:24pm UTC](https://discourse.vtk.org/t/cant-change-axis-labels-in-vtkchartxyz/3394/1 "2020-05-25T17:24:49Z")

</div>

Hello, in a vtkChartXY, I can just do this to change the title of an axis:

```auto
chart->GetAxis(0)->SetTitle("My excellent axis title");

```

However, in a vtkChartXYZ the equiavalent code doesn’t work and I always get the same title ‘X’. I can’t change any of the properties of the axis either.

Is there some other way I should be doing this? I certainly can’t find any examples or hints anywhere…

(I’m using version 9.0.0)

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.vtk.org/u/Kenichiro-Yoshimi)
#### Post date: [May 27, 2020, 12:31am UTC](https://discourse.vtk.org/t/cant-change-axis-labels-in-vtkchartxyz/3394/2 "2020-05-27T00:31:06Z")

</div>

Hello,

There is an example here:  
[https://lorensen.github.io/VTKExamples/site/Cxx/Plotting/BarChart/](https://lorensen.github.io/VTKExamples/site/Cxx/Plotting/BarChart/)

Could you specify the vtkAxis::BOTTOM variable for the axis index instead of 0 (= vtkAxis::LEFT)?

```auto
chart->GetAxis(vtkAxis::BOTTOM)->SetTitle("My excellent axis title");

```

---

<div class="post-metadata">

### Author: ![mdaley](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mdaley/32/1872_2.png) [@mdaley](https://discourse.vtk.org/u/mdaley)
#### Post date: [May 27, 2020, 7:32am UTC](https://discourse.vtk.org/t/cant-change-axis-labels-in-vtkchartxyz/3394/3 "2020-05-27T07:32:11Z")

</div>

Hi, thanks for the response. The example you linked to is using vtkChartXY. I know that setting axis titles works for that because I have used it. The problem is with vtkChartXYZ for 3D charts where the same thing does not work. I’m wondering about whether the 3D nature of the chart and how it is drawn might mean something else needs to be done? Or is it really the case that it just doesn’t work when it really should.

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.vtk.org/u/Kenichiro-Yoshimi)
#### Post date: [May 27, 2020, 10:18am UTC](https://discourse.vtk.org/t/cant-change-axis-labels-in-vtkchartxyz/3394/4 "2020-05-27T10:18:49Z")

</div>

Hello,

Ah, my apologies for misreading.

The ChartXYZ doesn’t seem to expose the axis label properties explicitly. Indeed, an example below shows the way to set axis labels as array names, but there is no way to set them directly.

> <https://github.com/Kitware/VTK/blob/master/Charts/Core/Testing/Cxx/TestChartXYZ.cxx>

I find a workaround by inheriting from vtkChartXYZ to be able to assign axis labels. Would you see the code snippet below?

```auto
class vtkMyChartXYZ : public vtkChartXYZ
{
public:
  static vtkMyChartXYZ* New();
  vtkTypeMacro(vtkMyChartXYZ, vtkChartXYZ);

  void SetXAxisLabel(const char *xAxisLabel)
  {
    this->XAxisLabel = xAxisLabel;
  }

  void SetYAxisLabel(const char *yAxisLabel)
  {
    this->YAxisLabel = yAxisLabel;
  }

  void SetZAxisLabel(const char *zAxisLabel)
  {
    this->ZAxisLabel = zAxisLabel;
  }
};
vtkStandardNewMacro(vtkMyChartXYZ);

int main(int, char *[])
{
  ...

  vtkNew<vtkMyChartXYZ> chart;

  chart->SetXAxisLabel("My excellent x axis title");
  chart->SetYAxisLabel("My excellent y axis title");
  chart->SetZAxisLabel("My excellent z axis title");

  ...
}

```

---

<div class="post-metadata">

### Author: ![mdaley](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mdaley/32/1872_2.png) [@mdaley](https://discourse.vtk.org/u/mdaley)
#### Post date: [May 27, 2020, 6:01pm UTC](https://discourse.vtk.org/t/cant-change-axis-labels-in-vtkchartxyz/3394/5 "2020-05-27T18:01:06Z")

</div>

Yoshimi-san,

Thank you very much for that suggestion. I shall certainly give it a try. It sounds just right.

Kind regards,

Matt

---

<div class="post-metadata">

### Author: ![mdaley](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mdaley/32/1872_2.png) [@mdaley](https://discourse.vtk.org/u/mdaley)
#### Post date: [May 27, 2020, 7:56pm UTC](https://discourse.vtk.org/t/cant-change-axis-labels-in-vtkchartxyz/3394/6 "2020-05-27T19:56:53Z")

</div>

OK, that worked really nicely. Next I’ll just have to get unicode working so I have have labels that are the Theta symbol instead of just text 😉 And then I want to change the font size! Things are a bit small on my 4K screen.

---

<div class="post-metadata">

### Author: ![mdaley](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mdaley/32/1872_2.png) [@mdaley](https://discourse.vtk.org/u/mdaley)
#### Post date: [May 27, 2020, 8:57pm UTC](https://discourse.vtk.org/t/cant-change-axis-labels-in-vtkchartxyz/3394/7 "2020-05-27T20:57:45Z")

</div>

Sad! To change the axes size I had to reimplement the whole class just to change a hardcoded value in DrawAxesLabels. And then, whilst the text can be made bigger there’s lots of overlapping of text going on. I guess vtkChartXYZ needs a bit of work to be more user friendly.

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.vtk.org/u/Kenichiro-Yoshimi)
#### Post date: [May 28, 2020, 2:55am UTC](https://discourse.vtk.org/t/cant-change-axis-labels-in-vtkchartxyz/3394/8 "2020-05-28T02:55:43Z")

</div>

Thanks for your patience. For improving the usability of vtkChartXYZ, you might want to open an issue here: [https://gitlab.kitware.com/vtk/vtk/issues](https://gitlab.kitware.com/vtk/vtk/issues)
