2013-07-23 1 views
-3

차트 1에서 오전 8시에 두 줄이 필요하고 오전 17시에만 두 번째 줄이 필요합니다.y 축에 타임 라인을 얻는 방법

내 MSchart 출력은입니다.

enter image description here

내 제안 출력은

enter image description here

내 aspx.cs 페이지 코드입니다

IQueryable<Agile.HelpDesk.Core.Entities.Incident> incidents = new IncidentManager().GetIncidentsByDate(startDate, endDate); 

     Chart1.Series["Series1"].Points.Clear(); 
     Chart1.Series["Series2"].Points.Clear(); 
     TimeSpan tsStart = new TimeSpan(08, 00, 00); 
     TimeSpan tsEnd = new TimeSpan(17, 00, 00); 

     foreach (Agile.HelpDesk.Core.Entities.Incident item in incidents) 
     { 
      if (item.OpenDate.TimeOfDay >= tsStart && item.OpenDate.TimeOfDay <= tsEnd) 
      { 
       Chart1.Series["Series1"].YValueType = ChartValueType.Time; 

       //Chart1.Series["Series1"].Points.AddXY(item.OpenDate, Convert.ToDouble(string.Format("{0:HH}.{0:mm}", item.OpenDate))); 
       Chart1.Series["Series1"].Points.AddXY(item.OpenDate, item.OpenDate); 

       string dayName = item.OpenDate.ToString("dddd"); 

       Chart1.Series["Series1"].Points[Chart1.Series["Series1"].Points.Count - 1].ToolTip = "Id : " + item.ID.ToString() + ", Open Date : " + item.OpenDate; 
       Chart1.Series["Series1"].Color = Color.Red; 
      } 
      else 
      { 
       Chart1.Series["Series2"].YValueType = ChartValueType.Time; 

       //Chart1.Series["Series2"].Points.AddXY(item.OpenDate, Convert.ToDouble(string.Format("{0:HH}.{0:mm}", item.OpenDate))); 
       Chart1.Series["Series2"].Points.AddXY(item.OpenDate, item.OpenDate); 
       Chart1.Series["Series2"].Points[Chart1.Series["Series2"].Points.Count - 1].ToolTip = "Id : " + item.ID.ToString() + ", Open Date : " + item.OpenDate; 
      } 
     } 

     //Chart1.Series["Series1"].YValueType = ChartValueType.Time; 
     //Chart1.Series["Series2"].YValueType = ChartValueType.Time; 

     Chart1.ChartAreas["ChartArea1"].AxisY.IntervalType = DateTimeIntervalType.Hours; 
     Chart1.ChartAreas["ChartArea1"].AxisY.Interval = 1; 

     Chart1.ChartAreas["ChartArea1"].AxisY.LabelStyle.Format = "HH:mm tt"; 

     Chart1.ChartAreas["ChartArea1"].AxisY.Title = "Time"; 
     Chart1.ChartAreas["ChartArea1"].AxisX.Title = "Date"; 

     //set Chart Marker Color 
     Chart1.Series["Series1"].MarkerColor = Color.LightBlue; 
     Chart1.Series["Series2"].MarkerColor = Color.Red; 

     // Set point chart type 
     Chart1.Series["Series1"].ChartType = SeriesChartType.Point; 
     Chart1.Series["Series2"].ChartType = SeriesChartType.Point; 

     // Enable data points labels 
     Chart1.Series["Series1"].IsValueShownAsLabel = false; 
     Chart1.Series["Series2"].IsValueShownAsLabel = false; 

     //Chart1.Series["Series1"]["LabelStyle"] = "Center"; 

     // Set marker size 
     Chart1.Series["Series1"].MarkerSize = 5; 
     Chart1.Series["Series2"].MarkerSize = 5; 

     // Set marker shape 
     Chart1.Series["Series1"].MarkerStyle = MarkerStyle.Circle; 
     Chart1.Series["Series2"].MarkerStyle = MarkerStyle.Circle; 

     // Enable 3D 
     //Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true; 
     UltraWebTab1.SelectedTab = 0; 
     UltraWebTab1.Visible = true; 

.aspx 페이지 코드

<asp:Chart ID="Chart1" runat="server" Width="812px" Height="696px" ImageLocation="~/temp/ChartPic_#SEQ(300,3)" 
           ImageType="Png" BackColor="WhiteSmoke" Palette="None" BorderColor="26, 59, 105" 
           BorderDashStyle="" BackSecondaryColor="White" BackGradientStyle="TopBottom" Visible="true" 
           BorderWidth="2" ImageStorageMode="UseImageLocation"> 
           <Legends> 
            <asp:Legend Enabled="False" IsTextAutoFit="False" Name="Default" BackColor="Transparent" 
             Font="Trebuchet MS, 8.25pt, style=Bold"> 
            </asp:Legend> 
           </Legends> 
           <BorderSkin SkinStyle="None"></BorderSkin> 
           <Series> 
            <asp:Series MarkerSize="10" Name="Series1" ChartType="Point" BorderColor="180, 26, 59, 105" 
             ShadowOffset="1" Font="Trebuchet MS, 9pt"> 
            </asp:Series> 
            <asp:Series MarkerSize="10" Name="Series2" ChartType="Point" BorderColor="180, 26, 59, 105" 
             ShadowOffset="1" Font="Trebuchet MS, 9pt"> 
            </asp:Series> 
           </Series> 
           <ChartAreas> 
            <asp:ChartArea Name="ChartArea1" BorderColor="64, 64, 64, 64" BorderDashStyle="Solid" 
             BackSecondaryColor="White" BackColor="Gainsboro" ShadowColor="Transparent" BackGradientStyle="TopBottom"> 
             <Area3DStyle Rotation="10" Perspective="10" Inclination="15" IsRightAngleAxes="false" 
              WallWidth="0" IsClustered="False" /> 
             <AxisY LineColor="64, 64, 64, 64" Minimum="0" Maximum="1"> 
              <LabelStyle Font="Trebuchet MS, 8.25pt" /> 
              <MajorGrid LineColor="64, 64, 64, 64" /> 
             </AxisY> 
             <AxisX LineColor="64, 64, 64, 64"> 
              <LabelStyle Font="Trebuchet MS, 8.25pt" /> 
              <MajorGrid LineColor="64, 64, 64, 64" /> 
             </AxisX> 
            </asp:ChartArea> 
           </ChartAreas> 
          </asp:Chart> 
+1

그냥 fyi : 시간은 '오후 5시'또는 '오후 17시'일 수 있습니다. – Andrei

+0

아니요 둘 다 원합니다. –

+0

내 차트에서 두 개의 수평선을 오전 8시에 1 초, 오전 2시에 오전 17시에 원합니다. –

답변

1
당신은이 같은 (첫 번째는 = = 17시 8시 다른 일정 일정) 차트 2 개의 새로운 상수 시리즈에 추가 또는 스트립 라인을 추가해야

:

 var sl = new System.Windows.Forms.DataVisualization.Charting.StripLine(); 
     sl.IntervalOffset = 8; 
     chart1.ChartAreas[0].AxisY.StripLines.Add(sl); 
+0

어떻게 가능합니까? 코드를 입력하십시오. 나는 MSchart를 처음 사용합니다. –

+0

수정 된 답변보기 –

+0

추가했지만 작동하지 않습니다. –

1

두 번째 스트립 라인을 (trippino의 대답)은 16:00에 추가되며 17:00은 필요하지 않습니다. 한 가지 해결 방법은 사용자 지정 레이블을 사용하고 8시에서 17시 사이의 영역을 강조 표시하는 것입니다.

Chart1.ChartAreas[0].AxisY.CustomLabels.Add(8, 17,"some label if needed"); 

다른 옵션은 차트에 두 개의 새로운 시리즈를 추가하는 것입니다. 하나는 8시에 다른 하나는 17시에. 시리즈의 포인트의 X 좌표는 차트의 최소 날짜부터 최대 날짜까지의 모든 날짜 여야하며 Y 좌표는 다른 라인의 경우 8:00 및 17:00이어야합니다.