2
#include <KDChartChart>
3
#include <KDChartBarDiagram>
4
#include <KDChartHeaderFooter>
5
#include <KDChartPosition>
6
#include <KDChartBackgroundAttributes>
7
#include <KDChartFrameAttributes>
9
using namespace KDChart;
11
class ChartWidget : public QWidget {
14
explicit ChartWidget(QWidget* parent=0)
18
m_model.insertRows( 0, 2, QModelIndex() );
19
m_model.insertColumns( 0, 3, QModelIndex() );
20
for (int row = 0; row < 3; ++row) {
21
for (int column = 0; column < 3; ++column) {
22
QModelIndex index = m_model.index(row, column, QModelIndex());
23
m_model.setData(index, QVariant(row+1 * column) );
27
BarDiagram* diagram = new BarDiagram;
28
diagram->setModel(&m_model);
30
m_chart.coordinatePlane()->replaceDiagram(diagram);
32
// Add at one Header and set it up
33
HeaderFooter* header = new HeaderFooter( &m_chart );
34
header->setPosition( Position::North );
35
header->setText( "A Simple Bar Chart" );
36
m_chart.addHeaderFooter( header );
38
// Configure the Header text attributes
40
hta.setPen( QPen( Qt::blue ) );
42
// let the header resize itself
43
// together with the widget.
44
// so-called relative size
46
m.setRelativeMode( header->autoReferenceArea(), KDChartEnums::MeasureOrientationMinimum );
50
m.setCalculationMode( KDChartEnums::MeasureCalculationModeAbsolute );
51
hta.setMinimalFontSize( m );
52
header->setTextAttributes( hta );
54
// Configure the header Background attributes
55
BackgroundAttributes hba;
56
hba.setBrush( Qt::white );
57
hba.setVisible( true );
58
header->setBackgroundAttributes( hba );
60
// Configure the header Frame attributes
62
hfa.setPen( QPen ( QBrush( Qt::darkGray ), 2 ) );
63
hfa.setVisible( true );
64
header->setFrameAttributes( hfa );
66
QVBoxLayout* l = new QVBoxLayout(this);
67
l->addWidget(&m_chart);
68
m_chart.setGlobalLeadingTop( 10 );
74
QStandardItemModel m_model;
77
int main( int argc, char** argv ) {
78
QApplication app( argc, argv );