简体   繁体   中英

Accumulate values in chart series - WPF DevExpress

I am creating several line series for a chart control in DevExpress at run-time. The series must be created at run-time since the number of series can vary from the data query I do. Here is how I create the series:

foreach (var item in lstSPCPrintID)
{
    string seriesName = Convert.ToString(item);
    LineSeries2D series = new LineSeries2D();
    dxcSPCDiagram.Series.Add(series);

    series.DisplayName = seriesName;

    var meas = from x in lstSPCChart
                where x.intSPCPrintID == item
                select new { x.intSPCMeas };

    foreach (var item2 in meas)
    {
        series.Points.Add(new SeriesPoint(item2.intSPCMeas));
    }
}

This happens inside a backgroundworker completed event and all the data needed is in the appropriate lists. In the test instance I am running, 6 series are created.

Each series consists of some test measurements that I need in the x-axis. These measurements can be the same value (and are the same value in a lot of cases). What I want then is for the y-axis to contain the count of how many times a measurement is for example -21. This will in the end create a curve.

Right now I create a series point for each measurement, but I do not know how to handle the ArgumentDataMember/ValueDataMember in this specific scenario. Is there a way for the chart to automatically do the counting or do I need to do it manually? Can anyone help me back on track?

I ended up doing a distinct count of the measurements before adding the series points.

foreach (var item in lstSPCPrintID)            
{
    string seriesName = String.Format("Position: {0}", Convert.ToString(item));
    LineStackedSeries2D series = new LineStackedSeries2D();
    series.ArgumentScaleType = ScaleType.Numerical;
    series.DisplayName = seriesName;
    series.SeriesAnimation = new Line2DUnwindAnimation();

    var meas = from x in lstSPCChart
               where x.intSPCPrintID == item
               select new { x.dblSPCMeas };

    var measDistinctCount = meas.GroupBy(x => x.dblSPCMeas).Select(group => new { Meas = group.Key, Count = group.Count() }).OrderBy(y => y.Meas);

    foreach (var item2 in measDistinctCount)
    {
        series.Points.Add(new SeriesPoint(item2.Meas, item2.Count));
    }

    dxcSPCDiagram.Series.Add(series);

    series.Animate();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM