Reputation: 3674
I have created a column chart in asp.net. I am showing the date on x-axis. At the moment the date is shown as dd/mm/yyyy. All I need is to show the date as dd-mm-yy and ideally Weekday, dd-mm-yy e.g. Monday, 12-05-15.
<asp:Chart ID="Chart1" runat="server" Height="400px" Width="900px" BorderWidth = "1">
<Series>
<asp:Series Name="Series1" XValueMember="uploaded_date" YValueMembers="value" ChartArea="ChartArea1" ChartType="Line" YValuesPerPoint="6" BorderWidth="6" >
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
<AxisY Title="Quantity" TitleForeColor="#ff0000" Interval="20">
<MajorGrid Enabled ="true" />
</AxisY>
<AxisX Title="Date" IsLabelAutoFit="True" TitleForeColor="#ff0000">
<MajorGrid Enabled ="False" />
</AxisX>
</asp:ChartArea>
</ChartAreas>
Upvotes: 0
Views: 2887
Reputation: 23937
Use formatting:
DateTime.Now.ToString("dddd, dd-MM-yy");
Output:
Montag, 15-06-15 //Written day of week in your local culture.
To edit the axis labeling, you can do it in your code-behind file:
Chart1.ChartAreas[0].AxisX.LabelStyle.Format = "dddd, dd-MM-yy";
Or in your markup:
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
<AxisX Title="Date" IsLabelAutoFit="True" TitleForeColor="#ff0000">
<LabelStyle Format="dddd, dd-MM-yy" />
<MajorGrid Enabled ="False" />
</AxisX>
</asp:ChartArea>
</ChartAreas>
Reference: https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
Upvotes: 1
Reputation: 6572
You can use the following:
place this in aspx page(html side)
<asp:Literal runat="server" ID="ltrDate"/>
and use this in page_load at backend(cs file)
ltrDate.Text = DateTime.Now.ToString("ddd") + ", " + DateTime.Now.ToString("dd-MM-yy");
Upvotes: 0