简体   繁体   中英

ASP Chart doesn't format correctly if XValueType=“Time” and Series contains DateTime which spans multiple days

I have to following code which displays a chart that represents data over a period of time. If all the data is from the same day, the chart displays correctly, and the X axis tick mark labels display time in hours. If the data spans two days, the graph wraps to the beginning and overlaps other points. If I set the XValueType="DateTime" the series plots correctly but the X axis tick mark labels become dates, even thought the IntervalType="Hours". Is there any way I can get the hours to display on the X axis without having the data wrap to the beginning of the chart?

<asp:Chart ID="Chart1" BackColor="Black" Width="400px" Height="125px" DataSource='<%# DataBinder.Eval(Container.DataItem, "Metrics") %>'
                                runat="server">
                                <Series>
                                    <asp:Series ChartType="Line" Name="Series1" YValueMembers="YValue" YValueType="Double"
                                        XValueMember="Time" XValueType="Time">
                                    </asp:Series>
                                </Series>
                                <ChartAreas>
                                    <asp:ChartArea Name="ChartArea1" BackColor="Black">
                                        <AxisY Interval="50" LineColor="White" IsStartedFromZero="true" Maximum="100">
                                            <MajorTickMark LineColor="White" Interval="10" />
                                            <LabelStyle ForeColor="White" />
                                        </AxisY>
                                        <AxisX LineColor="White" IntervalType="Hours">
                                            <LabelStyle ForeColor="White" />
                                            <MajorTickMark LineColor="White" />
                                        </AxisX>
                                    </asp:ChartArea>
                                </ChartAreas>
                            </asp:Chart>

I solved my problem by setting the XValueType="DateTime" and formatting the label on the x axis to display the time, not the date. The code for the x axis is now the following:

<AxisX LineColor="White" IntervalType="Hours">
      <LabelStyle ForeColor="White" Format="h:mm tt" />
      <MajorTickMark LineColor="White" />
</AxisX>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM