-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.8.0
-
None
QBarSeries is using a trick under the hood by using an XYDomain for its x-axis that runs -0.5 - [bar count - 1].5
When you attach an axis to the series, it initializes the underlying XYDomain to the actual numeric range of the axis, but BarChartItem expects the previously mentioned XYDomain based on the bar count.
It's fair to ask why you would want a numeric range for the axis under a bar chart, so here's the example of why I need this:
I've written a distribution visualization of surveyed data, say from 1 to 1,000,000. I want to show roughly where the data is grouped, so I create a bar chart of something like 100 bars. I then divide my data range (1,000,000 - 1) by the # of bars (100) to get a data range for each bar. Then I iterate over my data increment the count of each bar whenever data fits in its 'bucket'.
This all works fairly well. If I don't use attachAxis, I can create a QValueAxis with the appropriate data range and add it to the chart and it will render everything correctly. If, however, I call attachAxis (which should be benign) it will replace the bar count range with my actual data range. In this case, I get bars that are ~0.002 pixels wide (which is an incorrect calculation!), so they effectively disappear.
Another reasonable question is why I'm using attachAxis(). In this case, it's because I want an axis along the top that shows broad categories (using QCategoryAxis). To that requires attaching multiple axes to the series, but while I was working on this I noticed that just attaching the standard x & y axes I'd created broke the rendering of the bar chart.
There is a workaround, but it's crappy: remove the series from the chart and then add it again. This will re-initialize the internal XYDomain to the aforementioned bar count range.