File indexing completed on 2024-05-12 04:20:07

0001 /**
0002  * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
0003  *
0004  * This file is part of the KD Chart library.
0005  *
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #include "mainwindow.h"
0010 
0011 #include <KChartChart>
0012 #include <KChartAbstractCoordinatePlane>
0013 #include <KChartCartesianAxis>
0014 #include <KChartBarDiagram>
0015 
0016 
0017 #include <QDebug>
0018 #include <QPen>
0019 #include <QHBoxLayout>
0020 
0021 using namespace KChart;
0022 
0023 MainWindow::MainWindow( QWidget* parent ) :
0024     QWidget( parent )
0025 {
0026     QHBoxLayout* chartLayout = new QHBoxLayout( this );
0027     m_chart = new Chart();
0028     chartLayout->addWidget( m_chart );
0029 
0030     m_model.loadFromCSV( ":/data" );
0031 
0032     // Set up the diagram
0033     m_bars = new BarDiagram();
0034     m_bars->setModel( &m_model );
0035     m_bars->addAxis( new CartesianAxis( m_bars ) );
0036 
0037     m_chart->coordinatePlane()->replaceDiagram( m_bars );
0038 
0039     CartesianCoordinatePlane *plane 
0040             = dynamic_cast<CartesianCoordinatePlane*>( m_chart->coordinatePlane() );
0041     Q_ASSERT( plane );
0042     // The values in the model are all zero, so set the size of the plane 
0043     // to something that is non-zero manually
0044     plane->setVerticalRange( QPair<qreal, qreal>( -2.0, 2.0 ) );
0045 }
0046