2015-01-16 11 views
0

하나 이상의 데이터 세리가있는 ReportViewer에서 해당 차트 컨트롤을 사용하는 방법을 보여주는 샘플 코드를 찾을 수 없습니다. 동일한 reportviewer에서 엔진의 Setpoint 및 Feedback을 플로팅하고 싶지만 어떻게 진행해야할지 모릅니다.두 개 이상의 계열이 포함 된 C#의 ReportViewer 차트

데이터 원본으로 사용하는 몇 가지 사용자 지정 개체가 있습니다.

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; 
    } 
} 

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; } 
} 

내가 데이터 소스

<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> 

추가 내 프로젝트에 reportViwer로하는 Point2D를 추가 한 엔진 클래스 및 보고서에 그래프 (선) 삽입 ReportData에서 Point2D를 사용하여 그래프로 드래그했습니다. 이제 데이터 소스 "바인딩"을 설정했습니다.

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

잘 작동합니다. 한 시리즈를 보여줍니다.

피드백을 동일한 그래프에 추가하려면 어떻게해야합니까?

답변

0

좋아요. 해결책을 찾았습니다. 틀 렸으면 고쳐줘.

그래프에 더 많은 데이터 집합을 사용할 수없는 것 같습니다. 그래서 나는

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; } 
} 

을 다음과 같이> ... 같은 목록 <의 모든 포인트를 저장하는

변경을하고 결국 및 보고서에 내가 this change is to use the type to group the series by.

그것은 작동이 변경 한 것 하지만 하나의 List < ...> 3 대신에 끝났다. 아마도 세 개의 목록을 유지하면서 함수를 통해 연결 만 할 수는 있지만 ...이 솔루션으로 관리 할 수 ​​있습니다.