示例#1
0
MainWindow::MainWindow( QWidget* parent ) :
    QWidget( parent )
{
    setupUi( this );

    QHBoxLayout* chartLayout = new QHBoxLayout( m_chartFrame );
    m_chart = new KChart::Chart;
    chartLayout->addWidget( m_chart );

    m_model.loadFromCSV( ":/data" );

    // Set up the diagram
    m_lines = new KChart::LineDiagram();
    m_lines->setModel( &m_model );

    m_xAxis = new KChart::CartesianAxis( m_lines );
    KChart::TextAttributes ta( m_xAxis->textAttributes() );

    AdjustedCartesianAxis *yAxis = new AdjustedCartesianAxis( m_lines );
    yAxis->setBounds( 3, 6 );
    m_xAxis->setPosition( KChart::CartesianAxis::Bottom );
    yAxis->setPosition( KChart::CartesianAxis::Left );

// set the following to 0, to see the default Abscissa labels (== X headers, as read from the data file)
#if 1
    QStringList daysOfWeek;
    daysOfWeek << "Monday" << "Tuesday" << "Wednesday" << "Thursday" << "Friday" << "Saturday" << "Sunday";
    m_xAxis->setLabels( daysOfWeek );

    //QStringList shortDays;
    //shortDays << "Mon" << "Tue" << "Wed" << "Thu" << "Fri" << "Sat" << "Sun";
    //m_xAxis->setShortLabels( shortDays );
#endif

// Use HTML for drawing the text in the axis labels.
#if 0
    QStringList htmlStyles;
    htmlStyles << "<b>Bold</b>" << "<i>Italic</i>" << "<u>Underline</u>" << "<font color='red'>Red</font>";
    m_xAxis->setLabels( htmlStyles );
    ta.setTextDocument(new QTextDocument);
#endif

    // Illustration of custom ticks
    QList<qreal> ticks;
    ticks.append( 0.5 );
    ticks.append( 3.5 );
    ticks.append( 4.2 );
    ticks.append( 6.5 );
    m_xAxis->setCustomTicks(ticks);
    yAxis->setCustomTicks(ticks);

    // rotate abscissa labels by -60 degrees:
    ta.setRotation( -60 );

    m_xAxis->setTextAttributes( ta );
    m_lines->addAxis( m_xAxis );
    m_lines->addAxis( yAxis );
    m_chart->coordinatePlane()->replaceDiagram( m_lines );
    // Set up the legend
    m_xAxis->setCustomTickLength( 11 );
    yAxis->setCustomTickLength( 11 );
    m_legend = new KChart::Legend( m_lines, m_chart );
    m_legend->setPosition( KChart::Position::East );
    m_legend->setAlignment( Qt::AlignTop );
    m_chart->addLegend( m_legend );

    connect( m_annotations, SIGNAL( toggled( bool ) ), SLOT( annotationsToggled( bool ) ) );
    connect( m_linesOnAnnotations, SIGNAL( toggled( bool ) ), SLOT( gridLinesOnAnnotationsToggled( bool ) ) );
}
示例#2
0
MainWindow::MainWindow( QWidget* parent ) :
    QWidget( parent )
{
    setupUi( this );

    QHBoxLayout* chartLayout = new QHBoxLayout( chartFrame );
    m_chart = new KDChart::Chart;
    chartLayout->addWidget( m_chart );
    hSBar->setVisible( false );
    vSBar->setVisible( false );

    m_model.loadFromCSV( ":/data" );

    // Set up the diagram
    m_lines = new KDChart::LineDiagram();
    m_lines->setModel( &m_model );

    KDChart::CartesianAxis *xAxis = new KDChart::CartesianAxis( m_lines );
    KDChart::TextAttributes ta( xAxis->textAttributes() );

    AdjustedCartesianAxis *yAxis = new AdjustedCartesianAxis( m_lines );
    yAxis->setBounds( 3, 6 );
    xAxis->setPosition ( KDChart::CartesianAxis::Bottom );
    yAxis->setPosition ( KDChart::CartesianAxis::Left );

/*
// set the following to 0 to have only one of the axes with background
#if 1
    // colourize the axes' backgrounds
    KDChart::BackgroundAttributes ba = yAxis->backgroundAttributes();
    ba.setVisible( true );
    ba.setBrush( QBrush( QColor( 0xff, 0xff, 0x40 ) ) );
    yAxis->setBackgroundAttributes( ba );
    xAxis->setBackgroundAttributes( ba );
#else
    // colourize the Ordinate axis' background
    QLinearGradient linearGrad( QPointF( 0, 100 ), QPointF( 0, 400 ) );
    linearGrad.setColorAt( 0.0, QColor( 0xff, 0xff, 0xc0 ) );
    linearGrad.setColorAt( 1.0, QColor( 0xa0, 0xc0, 0xff ) );
    ba = yAxis->backgroundAttributes();
    ba.setVisible( true );
    ba.setBrush( linearGrad );
    yAxis->setBackgroundAttributes( ba );
#endif
*/
    // add 1 pixel space at the left and at the top edge, because the
    // axis area would otherwise overwrite the left/top borders
    m_chart->setGlobalLeading( 1, 1, 0, 0 );

// set the following to 0, to see the default Abscissa labels (== X headers, as read from the data file)
#if 1
    QStringList daysOfWeek;
    daysOfWeek << "Monday" << "Tuesday" << "Wednesday" << "Thursday" << "Friday" << "Saturday" << "Sunday";
    xAxis->setLabels( daysOfWeek );

    //QStringList shortDays;
    //shortDays << "Mon" << "Tue" << "Wed" << "Thu" << "Fri" << "Sat" << "Sun";
    //xAxis->setShortLabels( shortDays );
#endif

// Use HTML for drawing the text in the axis labels.
#if 0
    QStringList htmlStyles;
    htmlStyles << "<b>Bold</b>" << "<i>Italic</i>" << "<u>Underline</u>" << "<font color='red'>Red</font>";
    xAxis->setLabels( htmlStyles );
    ta.setTextDocument(new QTextDocument);
#endif


// set custom axis labels at custom positions
#if 0
    QMap< qreal, QString > annotations;
    annotations[ 0.5 ] = "Left";
    annotations[ 3.5 ] = "Center";
    annotations[ 4.2 ] = "After Center";
    annotations[ 6.5 ] = "Right";
    xAxis->setAnnotations(annotations);
#endif

    // Illustration of custom ticks
    QList<qreal> ticks;
    ticks.append( 0.5 );
    ticks.append( 3.5 );
    ticks.append( 4.2 );
    ticks.append( 6.5 );
    xAxis->setCustomTicks(ticks);
    yAxis->setCustomTicks(ticks);

    // rotate abscissa labels by -60 degrees:
    ta.setRotation( -60 );

    xAxis->setTextAttributes( ta );
    m_lines->addAxis( xAxis );
    m_lines->addAxis( yAxis );
    m_chart->coordinatePlane()->replaceDiagram( m_lines );
    // Set up the legend
    xAxis->setCustomTickLength( 11 );
    yAxis->setCustomTickLength( 11 );
    m_legend = new KDChart::Legend( m_lines, m_chart );
    m_legend->setPosition( KDChart::Position::East );
    m_legend->setAlignment( Qt::AlignTop );
    m_chart->addLegend( m_legend );
}
示例#3
0
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);
}