Page 1 of 1
Problem resizing a chart after drawing
Posted: Wed Mar 22, 2017 9:40 pm
by 16579733
Hi,
yet another problem I run into with my 'colorbar' emulation. What I tried to achive is to have a fixed size ColorBar but the Charts width should adjust to the width of the right-axis labels. I've attached a sample application. Just run it (you need Codesite installed) and see the log output (do not move with the mouse across anything on that app. yet!).
In the log you can see that in the AfterDraw event the previous Width was 98 and the new Width is 109.
Now just move the mouse over one of the labels and see the width of the chart "jumping" (in the log you can see that the with ist staying at 109)
Now click the 'Change scale' button (don't move the mouse across the labels).
In the chart you can see the lables change (getting wider) and the color bar is shrinking but In the log you can see that the old width was 109 and is changed to 121.
You could move over one of the lables again and see how the 'physical' Width changes again BUT instead press the 'set' button. Now the Width is adjusted but only with the following trick:
Code: Select all
CMapChart.Width := CMapChart.Width+1;
CMapChart.Width := CMapChart.Width-1;
Note also that this trick is not working in the AfterDraw event...
So I hope you know a way to adjust the charts width when the lables get bigger or smaller?
Re: Problem resizing a chart after drawing
Posted: Wed Mar 22, 2017 11:35 pm
by 16579733
In addition if you turn off Hover support, moving over the labels with the mouse does not resize the grid anymore
Re: Problem resizing a chart after drawing
Posted: Wed Mar 22, 2017 11:53 pm
by 16579733
Playing around with the app I found a way to change the width by using PostMessage, this brought up another problem (beside te flickering caused by the delayed adjustment of the Width property).
The attached demo allows to switch the scale by klicking 'Change scale' button but when cycling through the different settings you can see, that the absolute with of the colorbar is a little bit different for each situation. It seems the calculation of MaxLabelsWidth isn't accurate for my purpose?
What I would need is, that everything left of the lables does not change a single pixel. The label itself and the width of the chart should adjust to always show the values (and of course switching the scales should be flicker free).
Re: Problem resizing a chart after drawing
Posted: Fri Mar 24, 2017 2:45 pm
by yeray
Hello,
I haven't looked at the last message here yet, but I can explain the behaviour in the first application.
Note that, changing the width at OnAfterDraw event, has no visible effect until the next time the chart is drawn. This happens because when this event is called, the chart has already been drawn.
And the chart is being redrawn when you move the mouse over the labels - so the changes made at OnAfterDraw are considered - if the Hover feature is enabled.
I think all this is a behaviour to expect.
At this point, I'm not sure to understand what are you trying to achieve that made you think this is an abnormal behaviour.
Re: Problem resizing a chart after drawing
Posted: Fri Mar 24, 2017 3:06 pm
by yeray
Hello,
I think I now understand what you are trying to do.
Try adding this at your OnCreate:
Code: Select all
CMapChart.CustomChartRect:=True;
CMapChart.ChartRect:=Rect(3, 16, 58, 380);
CMapChart.RightAxis.ResizeChart:=False;
Re: Problem resizing a chart after drawing
Posted: Fri Mar 24, 2017 7:53 pm
by 16579733
very nice, that did the trick!!!
Re: Problem resizing a chart after drawing
Posted: Mon Mar 27, 2017 12:46 pm
by 16579733
... but it didn't solve the resize - issue.
So I switched to custom labels (i finally was able do access the custom labels demo) and do the resize after the custom labels are set.
So just in case someone needs that sort of behaviour, I attatched my latest working sample application...
Re: Problem resizing a chart after drawing
Posted: Mon Mar 27, 2017 3:40 pm
by 16579733
I run yet in another problem I was not able to solve. This time I supplied a "real" filter form my application and now when resising the bar (height) there is a black line appearing with some height-values:
- blackline.PNG (2.5 KiB) Viewed 16282 times
I have again attached a sample application. Please run it and resize the form (just the height!) and you will see that black line come and go depending on the forms height...
There seems to be also a problem with custom labels and resizeing the chart (again only the height).
If you run the sample and just resize the Forms height with the mouse you can see the number of labels increase as the bar gets taller or reduce as it gets smaller (see the image above as the numbers of labels has already decreased).
Now if you start the application again and first press "change scale" and then make ist smaller you get:
- labeloverflow.PNG (3.07 KiB) Viewed 16283 times
I'm sure this is because of the custom labels I use now. The question is: How can I let the chart deside how many labels are optimal for the current charts size but have them custom?
Re: Problem resizing a chart after drawing
Posted: Mon Mar 27, 2017 3:43 pm
by 16579733
...and here's sample....
Re: Problem resizing a chart after drawing
Posted: Mon Apr 03, 2017 1:25 pm
by yeray