Can't change axis labels in vtkChartXYZ?

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

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)

Hello,

There is an example here:
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)?

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

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.

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.

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

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");

  ...
}

Yoshimi-san,

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

Kind regards,

Matt

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 :wink: And then I want to change the font size! Things are a bit small on my 4K screen.

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.

1 Like

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