Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using Microsoft chart. in my chart I want Date and time wise point but date coming properly but time is not display properly.
C#

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(07, 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"].XValueType = ChartValueType.Time;
                    Chart1.Series["Series1"].Points.AddXY(item.OpenDate.ToString("HH:mm"), item.OpenDate);
                    Chart1.Series["Series1"].Points[Chart1.Series["Series1"].Points.Count - 1].ToolTip = "Id : " + item.ID.ToString() + ", Open Date : " + item.OpenDate;

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

                    //Chart1.Series["Series2"].YValueType = ChartValueType.Date;
                }
            }

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

            Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor = Color.Blue;

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

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


Html Code is


XML
<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">
                                               <LabelStyle Font="Trebuchet MS, 8.25pt" />
                                               <MajorGrid LineColor="AliceBlue" />
                                           </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

>
Posted
Updated 17-Jul-13 0:42am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900