I forgot to add the sample code I have (which is modified from the BarChart example). In the example, I've attached two x-axis objects to the plot, a QValueAxis located above the plot that puts tick marks and labels where I want them to be, but has the wrong values, and a QBarCategoryAxis located below the plot that has most of the values I want (there doesn't seem to be any way to have N+1 labels for N bins), but the labels are centered on the bins, not on the tick marks...
Sean Murphy Sr. Project Engineer Walbro LLC 4144 Doerr Rd Cass City, MI 48726 ph. 989 872 7274 cell 734 223 8975 fax. 989 872 3782 smur...@walbro.com<mailto:smur...@walbro.com> Confidentiality Notice: The materials contained within this e-mail transmission (including all attachments) are private and confidential and the property of the sender. The information contained in the materials is privileged and intended only for the named addressee(s). If you are not the intended addressee, be advised that any unauthorized disclosure, copying, distribution or the taking of any action in reliance on the contents of this material is strictly prohibited. If you have received this e-mail transmission in error, please immediately notify the sender by telephone at 989-872-7274 or send an e-mail to smur...@walbro.com<mailto:smur...@walbro.com> and thereafter destroy the e-mail you received and all copies thereof. From: Interest <interest-bounces+smurphy=walbro....@qt-project.org> On Behalf Of Murphy, Sean Sent: Tuesday, June 12, 2018 1:45 PM To: interest@qt-project.org Subject: [Interest] How to create custom chart/axis I'm trying to plot some data using QCharts and having trouble finding the combination of options that get me what I want, here's our setup: Underlying data: the underlying data is basically a set of bins, with a count of how many items are in that bin. The numerical range of each individual bin is non-uniform, i.e. the range of bin 0 may or may not equal the range of bin 1, which may or may not equal the range of bin 2, etc. Here's an example data set: Bin range # of items in bin 0-700 1 700-1200 2 1200-1800 3 1800-2800 4 2800-3800 5 3800-4200 6 So what you can see here is that there are 6 bins total, but there are 7 bin edges: 0, 700, 1200, 1800, 2800, 3800, 4200. Desired plot characteristics: we want the pixel width of each bin to be uniform regardless of the numerical range of the bin. We need to have the x-axis tick marks and labels correctly show the values of the bin edges. I've attached a photoshopped picture of the desired plot, you can see that the bins are all of equal pixel width, and that I've photoshopped the labels I want on the x-axis. Trying to create this using QChart classes seems to be a problem. 1. To get the bin spacing to be uniform, the best way to plot the data is to have the x values be 0,1,2,3,4,5 and the y values be the number of items in the bin (1,2,3,4,5,6). 2. Based on where I want the labels, QValueAxis seems closer to what I want because it puts the labels on the tick marks, and allows for the number of tick marks to be one greater than the number of bins, however there doesn't seem to be a way to have the axis's labels be values that aren't equal to the value of the tick mark in plot values. 3. QCategoryAxis (or QBarCategoryAxis) allow you to customize the string for each label, but seems to lock you in to number of labels equals number of bins. There doesn't seem to be an axis type that allows all of the above to coexist at the same time. So then I took a look at QAbstractAxis, wondering if I can create my own. The issue there is I don't see any way to override the text of an axis label or to get a pointer to any of the labels, etc. Is there any way to do this? Sean This message has been scanned for malware by Forcepoint. www.forcepoint.com<http://www.forcepoint.com/> Click here<https://www.mailcontrol.com/sr/iDHNIolXV47GX2PQPOmvUlHUcPnZ!qyDfNqCk519TFZ5PGFCHLa9YuAHHz0VcbnSJu!Oqka8PlrJaydNu2tBwg==> to report this email as spam.
barchart.pro
Description: barchart.pro
/**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Charts module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:GPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3 or (at your option) any later version ** approved by the KDE Free Qt Foundation. The licenses are as published by ** the Free Software Foundation and appearing in the file LICENSE.GPL3 ** included in the packaging of this file. Please review the following ** information to ensure the GNU General Public License requirements will ** be met: https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include <QtWidgets/QApplication> #include <QtWidgets/QMainWindow> #include <QtCharts/QChartView> #include <QtCharts/QBarSeries> #include <QtCharts/QBarSet> #include <QtCharts/QLegend> #include <QtCharts/QBarCategoryAxis> #include <QtCharts/QValueAxis> #include <QtCharts/QCategoryAxis> QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { QApplication a(argc, argv); QBarSet *set0 = new QBarSet("Test"); *set0 << 1 << 2 << 3 << 4 << 5 << 6 ; QBarSeries *series = new QBarSeries(); series->append(set0); QChart *chart = new QChart(); chart->addSeries(series); QStringList categories; // I really want to add 4200 on the line below and have the labels fall on // the tick marks, not in between them categories << "0" << "700" << "1200" << "1800" << "2800" << "3800"; QBarCategoryAxis *axis = new QBarCategoryAxis(); axis->append(categories); chart->createDefaultAxes(); chart->setAxisX(axis, series); QValueAxis *axisX = new QValueAxis; chart->addAxis(axisX, Qt::AlignTop); series->attachAxis(axisX); axisX->setTickCount(7); chart->legend()->setVisible(true); chart->legend()->setAlignment(Qt::AlignBottom); QChartView *chartView = new QChartView(chart); chartView->setRenderHint(QPainter::Antialiasing); QMainWindow window; window.setCentralWidget(chartView); window.resize(420, 300); window.show(); return a.exec(); }
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest