buy now
log in
MindFusion

Q: I want to create a stacked bar chart - how do I do this?

A: For a stacked bar chart you need to have two or more BarSeries - there is no limit to the count. Use the properties of each series to set its data and apprearance:

            BarSeries series1 = new BarSeries();
            series1.XData = new DoubleCollection() { 12, 34, 15, 67, 8};
            series1.YData = new DoubleCollection() { 1, 2, 3, 4, 5 };

            series1.BarType = BarType.HorizontalStack;

            barChart1.Series.Add(series1);
Do not forget to add each BarSeries to the Series collection of your chart. You can set the data through data binding - check the AxesSeries class to see a list of the properties for that.

Q: I want to know when the users clicks on a piece in my pie chart and want to show some details about the clicked piece. How is this done?

A: You can handle the MouseLeftButtonDown event and the HitTest method to check if the user has clicked on a pie piece. In this case your code would look like this:

	private void pieChart1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            List result = pieChart1.HitTest(e.GetPosition(pieChart1));

            if (result.Count > 0)
            {
                foreach (ChartElement element in result)
                {
                    if (element is PiePiece)
                    {
                        PiePiece hitPiece = element as PiePiece;
                        int index = hitPiece.PieceIndex;
                        int seriesIndex = hitPiece.SeriesIndex;
                        double value = hitPiece.PieceValue;
                    }
                }
            }
        } 
    

Q: I want to place my legend at the bottom of the chart - it shows to the right by default. Which is the way to do it?

A: The legend position is determined by its dock and alignment. When the legend is located at the bottom or top of the chart you must use HorizontalAlignment. When the legend is docked to the left or right, you can adjust its position with VerticalAlignment. Here is sample code that places a SeriesLegend to the bottom center of the chart:

            SeriesLegend legend = new SeriesLegend();
            LayoutPanel.SetDock(legend, Dock.Bottom);
            legend.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            pieChart1.Legends.Add(legend);
            

Copyright © 2001-2017 MindFusion LLC. All rights reserved.
Terms of Use - Contact Us