[Interest] How to create custom chart/axis

Murphy, Sean smurphy at walbro.com
Tue Jun 12 20:29:46 CEST 2018


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
smurphy at walbro.com<mailto:smurphy at 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 smurphy at walbro.com<mailto:smurphy at walbro.com> and thereafter destroy the e-mail you received and all copies thereof.

From: Interest <interest-bounces+smurphy=walbro.com at qt-project.org> On Behalf Of Murphy, Sean
Sent: Tuesday, June 12, 2018 1:45 PM
To: interest at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180612/0d7f67de/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: barchart.pro
Type: application/octet-stream
Size: 121 bytes
Desc: barchart.pro
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180612/0d7f67de/attachment.obj>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: main.cpp
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180612/0d7f67de/attachment.ksh>


More information about the Interest mailing list