[Interest] How to create custom chart/axis

Murphy, Sean smurphy at walbro.com
Tue Jun 12 19:44:33 CEST 2018


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180612/e5fd8a0b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: desired.png
Type: image/png
Size: 25788 bytes
Desc: desired.png
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180612/e5fd8a0b/attachment.png>


More information about the Interest mailing list