2014-12-13 91 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