0

I seem unable to find sample code showing how to use that chart control in ReportViewer with more that one data serie. I want to plot Setpoint and Feedback from an Engine in the same reportviewer, but I have no idea on how to go about it.

I have a few custom objects that I use as datasource.

public class Point2D
{
    public double Value { get; private set; }
    public DateTime DateTime { get; private set; }

    public Point2D( double value, DateTime datetime)
    {
        Value = value;
        DateTime = datetime;
    }
}

and an Engine class

public class Engine
{
    public Engine(string Name)
    {
        this.Name = Name;
        Setpoint = new List<Point2D>();
        Feedback  = new List<Point2D>();
        Estimate = new List<Point2D>();

        foreach(int i in Enumerable.Range(0,101))
        {
            DateTime dt = DateTime.Now;
            double d = i / 100.0;
            Setpoint.Add(new Point2D(d, dt.AddSeconds(i)));
            Feedback.Add(new Point2D(d, dt.AddSeconds(i)));
            Estimate.Add(new Point2D(d, dt.AddSeconds(i)));
        }
    }
    public string Name { get; private set; }
    public List<Point2D> Setpoint { get; private set; }
    public List<Point2D> Feedback { get; private set; }
    public List<Point2D> Estimate { get; private set; }
}

I have added the Point2D as a datasource

<GenericObjectDataSource DisplayName="Point2D" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
   <TypeInfo>Point2D, ReportViewer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
</GenericObjectDataSource>

Added a reportViwer to my project, and inserted a graph (line) to the report used the Point2D from ReportData and dragged that into the graph. Now i set the datasource "binding"

this.Point2DBindingSource.DataSource = tdDataSource.Engines.First().Setpoint;

This works just fine. Showing me one series.

How do I go about adding the Feedback into the same graph?

schultz
  • 316
  • 2
  • 14

1 Answers1

0

Ok I found a solution of sorts. Correct me if i'm wrong.

The problem seems that you cannot use more that one dataset for the graph. So what i ended up doing is storing all the points in the same List<...>

Changes as follows

public class Point2D
{
    // made this type so i have more control of what i legal to add
    // idea from here: http://stackoverflow.com/questions/424366/c-sharp-string-enums
    public sealed class PointType
    {
        private int type;
        private string name;

        public static readonly PointType SETPOINT = new PointType(0, "SETPOINT");
        public static readonly PointType FEEDBACK = new PointType(1, "FEEDBACK");
        public static readonly PointType ESTIMATE = new PointType(2, "ESTIMATE");

        private PointType(int Type, string Name)
        {
            this.type = Type;
            this.name = Name;
        }

        public override String ToString() 
        { 
            return name; 
        }
    }

    public String Type { get; private set; }
    public double Value { get; private set; }
    public DateTime DateTime { get; private set; }

    public Point2D( double value, DateTime datetime, Point2D.PointType type)
    {
        Value = value;
        DateTime = datetime;
        Type = type.ToString();
    }
}

public class Engine
{
    public Engine(string Name)
    {
        this.Name = Name;
        Datapoints = new List<Point2D>();

        foreach(int i in Enumerable.Range(0,101))
        {
            DateTime dt = DateTime.Now;
            double d = i / 100.0;
            Datapoints.Add(new Point2D(d, dt.AddSeconds(i),Point2D.PointType.SETPOINT));
            Datapoints.Add(new Point2D(d, dt.AddSeconds(i+5),Point2D.PointType.FEEDBACK));
            Datapoints.Add(new Point2D(d, dt.AddSeconds(i + 2), Point2D.PointType.ESTIMATE));
        }
    }
    public string Name { get; private set; }
    public List<Point2D> Datapoints { get; private set; }
}

and to the report i made this change this change is to use the type to group the series by.

It works but i ended up with one List<...> instead of three. I probably could keep my three lists and just concat them via a function... But Ill manage with this solution.

schultz
  • 316
  • 2
  • 14