2013-07-23 30 views
-3

我只需要在上午8:00的第一個圖表和第二個在上午17:00 AM的兩條線。如何獲得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

Just fyi:time can be'5:00 PM' or'17:00' – Andrei

+0

不,我不想。 –

+0

我希望我的圖表上有兩條水平線,分別是上午8:00和上午17:00的secon。 –

回答

1

你必須添加到圖表2新常量系列(第一個是常數= 8:00另一常數= 17:00)或添加一個帶狀線,是這樣的:

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

怎麼可能。請給我提供代碼。我是MSchart的新手。 –

+0

嘗試編輯答案 –

+0

我已經添加了這個,但它不工作。 –

1

第二帶狀線(根據需要將在16:00和17:00增加trippino的答案)。一種解決方法是使用自定義標籤並在8:00至17:00之間突出顯示該區域。

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

由trippino指出的另一種選擇是將兩個新系列添加到圖表中。一個爲8:00,另一個爲17:00。系列中點的X座標應該是圖表中從最小值到最大值日期的所有日期,Y座標應爲8:00,然後17:00爲另一行。