[vtkusers] Direction of chart axes

Vasin Max max.vasin at outlook.com
Wed Mar 15 07:30:36 EDT 2017


Hello, VTK users!

I would line to flip the left axis of a vtkChart (i.e. to have the minimum value at the top and maximum at the bottom). 
So far I have managed to do this with the FIXED vtkAxis behavior and manual assignment of Minimum and Maximum
Properties of the axis.

Is this the correct way to do?

Can I combine flipping the axis and automatic scaling of it? If I comment out LINE 1, LINE 2 and LINE 3 (see below) the GetMaximum and GetMinimum after
plotCurve->SetInputData return 6.66 and 0.

How can I get zoom using mouse wheel working? Right now when the range on the bottom axis shrinks the range on the left axis grows. Restoring the zoom with R key
does not work.

The code of my test program follows. I am using VTK 7.1.0.
Thanks in advance.

#include <QtWidgets/QApplication>
#include <QVTKWidget.h>
#include <vtkAxis.h>
#include <vtkCamera.h>
#include <vtkChartXY.h>
#include <vtkContextScene.h>
#include <vtkContextView.h>
#include <vtkPlotPoints.h>
#include <vtkRenderer.h>
#include <vtkTable.h>
#include <vtkFloatArray.h>
#include <vtkSmartPointer.h>
#include <vtkRenderWindow.h>
#include <vtkPolyDataMapper.h>
#include <vtkVariantArray.h>

int main(int argc, char* argv[])
{
  QApplication app(argc, argv);

  QVTKWidget widget;
  widget.resize( 256, 256 );
 
  auto plotView = new QVTKWidget;

  auto chart = vtkSmartPointer<vtkChartXY>::New();
  chart->GetAxis(vtkAxis::LEFT)->SetTitle("Sine");
  chart->GetAxis(vtkAxis::LEFT)->SetMinimum(1.0); // LINE 1
  chart->GetAxis(vtkAxis::LEFT)->SetMaximum(-1.0); // LINE 2
  chart->GetAxis(vtkAxis::LEFT)->SetBehavior(vtkAxis::FIXED); // LINE 3

  auto plotCurve = chart->AddPlot(vtkChart::LINE);
  auto table = vtkSmartPointer<vtkTable>::New();
  auto xs = vtkSmartPointer<vtkFloatArray>::New();
  auto ys = vtkSmartPointer<vtkFloatArray>::New();

  xs->SetName("X");
  ys->SetName("Y");

  for (auto i = 0.0; i < 10.0; i+=0.1) {
    xs->InsertNextValue(i);
    ys->InsertNextValue(sin(i));
  }

  table->AddColumn(xs);
  table->AddColumn(ys);

  plotCurve->SetInputData(table, 0, 1);

  auto chartView = vtkSmartPointer<vtkContextView>::New();
  chartView->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
  chartView->GetScene()->AddItem(chart);

  chartView->SetInteractor(plotView->GetInteractor());
  plotView->SetRenderWindow(chartView->GetRenderWindow());

  plotView->setMinimumSize(500, 600);
  plotView->show();

  app.exec();
}

--
WBR,
Max Vasin.


More information about the vtkusers mailing list