[vtkusers] vtkQtBarChart help
Lodron, Gerald
Gerald.Lodron at joanneum.at
Wed Sep 15 04:33:36 EDT 2010
Hi
I want to make a 2D bar chart whereby the bars specify the ammount of volumina change (double value) of a region. So i want to display the name of the region on horizontal axis and and the value on vertical.
I already made it with vtkQtBarChart but i have no idea how i could display text on horizontal axis, here my code:
m_poDialog = new QDialog;
m_poChartWidget = new vtkQtChartWidget(m_poDialog);
QBoxLayout* poLayout = new QBoxLayout(QBoxLayout::Direction::TopToBottom, m_poDialog);
poLayout->addWidget(m_poChartWidget);
m_poArea = m_poChartWidget->getChartArea();
m_poBarChart = new vtkQtBarChart();
m_poArea->insertLayer( m_poArea->getAxisLayerIndex(), m_poBarChart );
vtkQtChartLegend *poLegend = new vtkQtChartLegend(m_poChartWidget);
vtkQtChartLegendManager *poManager = new vtkQtChartLegendManager(poLegend);
poManager->setChartLegend(poLegend);
poManager->setChartArea(m_poArea);
m_poChartWidget->setLegend(poLegend);
vtkQtChartMouseSelection *poSelector =vtkQtChartInteractorSetup::createDefault(m_poArea);
vtkQtChartSeriesSelectionHandler *poHandler = new vtkQtChartSeriesSelectionHandler(poSelector);
poHandler->setModeNames("Bar Chart - Series", "Bar Chart - Bars");
poHandler->setMousePressModifiers(Qt::ControlModifier, Qt::ControlModifier);
poHandler->setLayer(m_poBarChart);
poSelector->addHandler(poHandler);
poSelector->setSelectionMode("Bar Chart - Bars");
vtkQtChartInteractorSetup::setupDefaultKeys(m_poArea->getInteractor());
// Hide the x-axis grid.
vtkQtChartAxisLayer *axisLayer = m_poArea->getAxisLayer();
vtkQtChartAxis *xAxis = axisLayer->getAxis(vtkQtChartAxis::Bottom);
xAxis->getOptions()->setGridVisible(false);
xAxis->getOptions()->setLabelsVisible(true);
// Set up the poModel for the bar chart.
m_poTable = new vtkQtChartTableSeriesModel(0, m_poBarChart);
m_poBarChart->setModel(m_poTable);
QStandardItemModel *poModel = qobject_cast<QStandardItemModel *>(m_poTable->getItemModel());
if(poModel)
{
m_poTable->setItemModel(0);
delete poModel;
}
int iRows = poInput->GetVoluminaChanges()->size();
// Create a new item poModel for the file.
poModel = new QStandardItemModel(iRows, 1, m_poTable);
poModel->setItemPrototype(new QStandardItem());
//QStringList oLabels;
for(unsigned int nRow = 0; nRow < iRows; nRow++)
{
poModel->setVerticalHeaderItem(nRow, new QStandardItem));
poModel->verticalHeaderItem(nRow)->setData(QVariant((int)nRow), Qt::DisplayRole);
}
poModel->setHorizontalHeaderItem(0, new QStandardItem("Volumina change in %"));
for(unsigned int nRow = 0; nRow < iRows; nRow++)
{
poModel->setItem(nRow, 0, new QStandardItem(""));
poModel->item(nRow, 0)->setData(dVoluminaChange[nRow], Qt::DisplayRole);
}
// Set the new poModel in the chart.
m_poTable->setItemModel(poModel);
m_poDialog->show();
best regards
Gerald Lodron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100915/4d836863/attachment.htm>
More information about the vtkusers
mailing list