Search code examples
c#devexpressxtrareportdevexpress-windows-ui

Devexpress: How to add a control to below the other control in XtraReport


I use XtraReport to show my report. I want to add my chart to below the other one. Here is my code to add a new chart on XtraReport.

foreach (Control viewControl in Panel.Controls)
{
    if (viewControl.GetType() == typeof(ChartControl))
    {
        XRChart chart = new XRChart();

        ChartControl chartControl = viewControl as ChartControl;

        if (chartControl != null)
        {
            foreach (ISeries series in chartControl.Series)
            {
                Series s = new Series(series.Name, ViewType.Bar);
                s.Points.Add(
                    new SeriesPoint(
                        series.Points.First().UserArgument.ToString(), 
                        series.Points.First().UserValues.FirstOrDefault()
                    )
                );
                chart.Series.Add(s);
            }

            myReport.Detail.Controls.Add(chart);
        }
    }
}

I could not find the way to insert a break line between two XtraChart.


Solution

  • You need to indent your charts by using XRControl.TopF property. The value of indent you can get from the XRControl.BottomF property of previous chart.
    Here is example:

    float topF = 0;
    
    foreach (Control viewControl in Panel.Controls)
    {    
        var chartControl = viewControl as ChartControl;
    
        if (chartControl == null)
            continue;
    
        var chart = new XRChart();
    
        foreach (ISeries series in chartControl.Series)
        {
            var s = new Series(series.Name, ViewType.Bar);
            s.Points.Add(
                new SeriesPoint(
                    series.Points.First().UserArgument.ToString(), 
                    series.Points.First().UserValues.FirstOrDefault()
                )
            );
            chart.Series.Add(s);
        }
    
        chart.TopF = topF; // Indent chart.
        topF = chart.BottomF; // Set next value to the topF.
    
        myReport.Detail.Controls.Add(chart);    
    }