KReportChartView::KReportChartView(QWidget* parent) : KDChart::Chart(parent), m_backgroundBrush(KColorScheme(QPalette::Current).background()), m_foregroundBrush(KColorScheme(QPalette::Current).foreground()) { // ******************************************************************** // Set KMyMoney's Chart Parameter Defaults // ******************************************************************** //Set the background obtained from the color scheme BackgroundAttributes backAttr(backgroundAttributes()); backAttr.setBrush(m_backgroundBrush); backAttr.setVisible(true); setBackgroundAttributes(backAttr); //Line diagram KDChart::LineDiagram* diagram = new KDChart::LineDiagram; diagram->setModel(&m_model); this->coordinatePlane()->replaceDiagram(diagram); }
MainWindow::MainWindow( QWidget* parent ) : QWidget( parent ) { setupUi( this ); m_chartLayout = new QHBoxLayout( chartFrame ); m_chart = new KDChart::Chart(); m_chartLayout->addWidget( m_chart ); // add a small left-side leading because we use a coloured Y axis background m_chart->setGlobalLeadingLeft( 1 ); initializeDataModel(); // register our own serializer for saving / loading the Y axis: KDChart::registerElementSerializer< AdjustedCartesianAxisSerializer, AdjustedCartesianAxis >( 0 ); // will be un-registered in ~Mainwindow() // Set up the diagrams KDChart::LineDiagram* lines = new KDChart::LineDiagram(); lines->setModel( m_model ); // increase the line width for ( int iRow = 0; iRow < lines->model()->rowCount(); ++iRow ) { QPen pen( lines->pen( iRow ) ); pen.setWidth(2); pen.setColor( pen.color().dark(133) ); lines->setPen( iRow, pen ); } // Assign some axes KDChart::CartesianAxis *xAxis = new KDChart::CartesianAxis( lines ); AdjustedCartesianAxis *yAxis = new AdjustedCartesianAxis( lines ); yAxis->setBounds(29.9, 31.0); xAxis->setPosition ( KDChart::CartesianAxis::Bottom ); yAxis->setPosition ( KDChart::CartesianAxis::Left ); yAxis->setTitleText ( "an axis class with customized labels" ); lines->addAxis( xAxis ); lines->addAxis( yAxis ); KDChart::CartesianCoordinatePlane* plane = static_cast< KDChart::CartesianCoordinatePlane * >(m_chart->coordinatePlane()); plane->replaceDiagram( lines ); KDChart::HeaderFooter* headerFooter = new KDChart::HeaderFooter( m_chart ); m_chart->addHeaderFooter( headerFooter ); headerFooter->setText( "Line diagram using a custom axis class" ); KDChart::TextAttributes textAttrs( headerFooter->textAttributes() ); textAttrs.setPen( QPen( Qt::red ) ); headerFooter->setTextAttributes( textAttrs ); headerFooter->setType( KDChart::HeaderFooter::Header ); headerFooter->setPosition( KDChart::Position::North ); // assign some bg colors KDChart::BackgroundAttributes ba = yAxis->backgroundAttributes(); ba.setVisible(true); ba.setBrush(QBrush(QColor(255,255,200))); yAxis->setBackgroundAttributes(ba); }