Hello, I'm using pie chart to display OLAP data. I would like to utilize all space given to this control. At the beginning there is one chart which I would like the chart to be as large as it can and when drilling down, the more charts I have the smaller they will be. Currently I am able to set up ItemHeight and ItemWidth statically, is it possible to adjust size based on chart count, eg. by specifying MinHeight and MaxHeight?
Best regards,
Jan
Hello Jan,
Thank you for your post. I have been looking into it and I created a sample project for you showing how you can achieve the functionality you want. Basically I handled the FlatDataSource’s ResultChanged and the XamOlapPieChart’s SizeChanged events, where I call a method in which you should set the XamOlapPieChart’s ItemHeight and ItemWidth Properties. I added variables for the Window’s Height and Width and XamPieChart’s Items count, which you can use in order to calculate the measures that will best suit your requirement. Please let me know if need further clarifications on this matter.
Looking forward for your reply.
Hello,
thanks, your sample helped to access internal implementation of XamOlapPieChart. I modified it a little:
panel.VerticalAlignment = VerticalAlignment.Stretch;double fullWidth = panel.ActualWidth;
to get actual width of control not the whole Window as this is not the only control. For height this doesn't work, so I had to use height of whole XamOlapPieChart.
For DataSourceChange it works correctly, but on ResultChanged event property panel.Children.Count shows previous chart count . I use component version 13.1 and this behaviour is the same in my app and in your sample. Does it work with 14.1 for you?
Regards,
You can wrap the code in the SetDimensions method in a Dispatcher like this:
public void SetDimensions(XamOlapPieChart olapChart) { Dispatcher.BeginInvoke(new Action(() => { OlapPieChartItemsPanel panel = Utilities.GetDescendantFromType(olapChart, typeof(OlapPieChartItemsPanel), true) as OlapPieChartItemsPanel; int pieChartCount = panel.Children.Count; double windowHeight = this.ActualHeight; double windowWidth = this.ActualWidth; //Here you can set the "olapChart" ItemHeigh and ItemWidth based on the "pieChartCount" and Window's size }), System.Windows.Threading.DispatcherPriority.Background, null); }
in order to get the correct count.
Works like a charm. I learned something new about WPF Dispatcher. Thank you!
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.