2014-12-13 77 views
0

是否可以在标签的末尾绘制轴标签? 详见图片:vtk图表 - 如何在轴线的末端绘制轴标签?

http://habrastorage.org/files/94f/41a/b18/94f41ab1897a4bde815644bf287b4af9.png

如果可能的话,怎么样?

vtkNew<vtkContextView> contextView; 

vtkNew<vtkTable> table; 
vtkNew<vtkChartXY> chart; 
vtkNew<vtkDoubleArray> timeAxis; 
vtkNew<vtkDoubleArray> realDataAxis; 
vtkNew<vtkDoubleArray> measuredDataAxis; 

// ... 

contextView->SetInteractor(vtkWidget->GetInteractor()); 
vtkWidget->SetRenderWindow(contextView->GetRenderWindow()); 

timeAxis->SetName("t"); 
realDataAxis->SetName("x(t)"); 
measuredDataAxis->SetName("x*(t)"); 

table->AddColumn(timeAxis.Get()); 
table->AddColumn(realDataAxis.Get()); 
table->AddColumn(measuredDataAxis.Get()); 

chart->SetShowLegend(true); 
auto legend = chart->GetLegend(); 
legend->GetLabelProperties()->SetFontSize(14); 
legend->GetLabelProperties()->SetFontFamilyToTimes(); 

auto xAxis = chart->GetAxis(vtkAxis::BOTTOM); 
xAxis->SetTitle(QApplication::translate("DataSetChartWidget", "t").toStdString()); 

auto xTitleProps = xAxis->GetTitleProperties(); 
xTitleProps->SetFontSize(14); 
xTitleProps->SetFontFamilyToTimes(); 

auto xLabelProps = xAxis->GetLabelProperties(); 
xLabelProps->SetFontSize(14); 
xLabelProps->SetFontFamilyToTimes(); 

auto yAxis = chart->GetAxis(vtkAxis::LEFT); 
yAxis->SetTitle(QApplication::translate("DataSetChartWidget", "x(t), x*(t)").toStdString()); 

auto yTitleProps = yAxis->GetTitleProperties(); 
yTitleProps->SetFontSize(14); 
yTitleProps->SetFontFamilyToTimes(); 

auto yLabelProps = yAxis->GetLabelProperties(); 
yLabelProps->SetFontSize(14); 
yLabelProps->SetFontFamilyToTimes(); 

contextView->GetScene()->AddItem(chart.Get()); 

和代码绘制:

auto realPlot = chart->AddPlot(vtkChart::LINE); 
realPlot->SetInputData(table.Get(), 0, 1); 

auto measuredPlot = chart->AddPlot(vtkChart::POINTS); 
measuredPlot->SetInputData(table.Get(), 0, 2); 

回答

1

您可以设置轴标题的垂直和水平位置。

例如

myVtkChart->GetAxis(0)->GetTitleProperties()->SetJustificationToLeft(); 
你的情况

就应该足够叫

xTitleProps->SetJustificationToRight(); 
yTitleProps->SetJustificationToLeft(); 

但似乎标题宽度不缩放到轴的长度。 这意味着它可能需要将一些空格放入标题字符串中以获得预期结果。

+0

这不起作用... – Anton 2014-12-15 15:21:24

+0

对不起,误解了你的问题......我改变了答案。 – JohnnyQ 2014-12-15 15:35:15

+0

对不起,但这也行不通... – Anton 2014-12-15 16:01:43