File indexing completed on 2024-11-24 03:57:46

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 <QApplication>
0010 #include <KChartWidget>
0011 #include <KChartLineDiagram>
0012 #include <KChartCartesianAxis>
0013 #include <KChartDataValueAttributes>
0014 
0015 using namespace KChart;
0016 
0017 int main( int argc, char** argv ) {
0018     QApplication app( argc, argv );
0019 
0020     Widget widget;
0021     widget.resize( 600, 600 );
0022 
0023     QVector< qreal > vec1;
0024 
0025     vec1 << 25 << 16 << 9 << 4 << 1 << 0
0026          << 1 << 4 << 9 << 16 << 25;
0027 
0028     // assign your datasets
0029     // while setting the legend
0030     // items text
0031     widget.setDataset( 0, vec1, "vec1" );
0032 
0033 
0034     // add and position
0035     widget.addLegend(Position::North);
0036 
0037     // configure the axes
0038     CartesianAxis *xAxis = new CartesianAxis( widget.lineDiagram() );
0039     CartesianAxis *yAxis = new CartesianAxis (widget.lineDiagram() );
0040     xAxis->setPosition ( CartesianAxis::Bottom );
0041     yAxis->setPosition ( CartesianAxis::Left );
0042     xAxis->setTitleText ( "Abscissa bottom position" );
0043     yAxis->setTitleText ( "Ordinate left position" );
0044 
0045     // configure Xaxis labels
0046     // no need to re-write labels it iterates until all
0047     // labels are written
0048     QStringList daysOfWeek;
0049     daysOfWeek << "Monday" << "Tuesday" << "Wednesday";
0050     QStringList shortDays;
0051     shortDays << "Mon" << "Tue" << "Wed";
0052 
0053     // set user configured x axis labels
0054     xAxis->setLabels( daysOfWeek );
0055     xAxis->setShortLabels(  shortDays );
0056 
0057     widget.lineDiagram()->addAxis( xAxis );
0058     widget.lineDiagram()->addAxis( yAxis );
0059 
0060     // show data values
0061     DataValueAttributes a( widget.lineDiagram()->dataValueAttributes() );
0062     a.setVisible( true );
0063     widget.lineDiagram()->setDataValueAttributes( a );
0064 
0065     // make sure data values are displayed at the borders
0066     widget.setGlobalLeading( 20, 20, 20, 20 );
0067 
0068     widget.show();
0069 
0070     return app.exec();
0071 }