缺少X轴的Asp值:图表

时间:2017-08-05 09:12:13

标签: c# asp.net .net charts mschart

您好我刚刚完成了针对X轴和Y轴的我的asp条形图的数据绑定,但我面临一个奇怪的问题..

我实际上将X轴设置为1月,2月,3月,10月,11月和12月。但只有偶数月份出现(2月,4月,10月,12月)

代码我正在使用,

        String username = Session["ConsumerSelected"].ToString();

        AuditNLoggingDAO al = new AuditNLoggingDAO();

        String[] month = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
        "Jul", "Aug", "Sept", "Oct", "Nov", "Dec" };

        int[] monthLogin = { al.janLogin(username), al.febLogin(username), al.marLogin(username), al.aprLogin(username), al.mayLogin(username),
        al.junLogin(username), al.julyLogin(username), al.augLogin(username), al.septLogin(username), al.octLogin(username), al.novLogin(username), al.decLogin(username) };

        int[] monthLogout = { al.janLogout(username), al.febLogout(username), al.marLogout(username), al.aprLogout(username), al.mayLogout(username),
        al.junLogout(username), al.julyLogout(username), al.augLogout(username), al.septLogout(username), al.octLogout(username), al.novLogout(username), al.decLogout(username) };

        int[] monthFailure = { al.janFailure(username), al.febFailure(username), al.marFailure(username), al.aprFailure(username), al.mayFailure(username),
        al.junFailure(username), al.julyFailure(username), al.augFailure(username), al.septFailure(username), al.octFailure(username), al.novFailure(username), al.decFailure(username) };

        int[] monthPW = { al.janPW(username), al.febPW(username), al.marPW(username), al.aprPW(username), al.mayPW(username), al.junPW(username), al.julyPW(username), al.augPW(username), al.septPW(username),
         al.octPW(username), al.novPW(username), al.decPW(username) };

        Series seriesLogin = ChartMonth.Series.Add("SeriesLogin");
        seriesLogin.Color = ColorTranslator.FromHtml("#5cb85c");
        seriesLogin.LegendText = "Number of Login Executes";
        seriesLogin.IsValueShownAsLabel = true;
        seriesLogin.Font = new Font("Microsoft Sans Serif", 11);
        seriesLogin.SmartLabelStyle.Enabled = false;

        ChartMonth.Series["SeriesLogin"].Points.DataBindXY(month, monthLogin);

        Series seriesLogout = ChartMonth.Series.Add("SeriesLogout");
        seriesLogout.Color = ColorTranslator.FromHtml("#f0ad4e");
        seriesLogout.LegendText = "Number of Logout Executes";
        seriesLogout.IsValueShownAsLabel = true;
        seriesLogout.Font = new Font("Microsoft Sans Serif", 11);
        seriesLogout.SmartLabelStyle.Enabled = false;

        ChartMonth.Series["SeriesLogout"].Points.DataBindXY(month, monthLogout);

        Series seriesFailure = ChartMonth.Series.Add("SeriesFailure");
        seriesFailure.Color = ColorTranslator.FromHtml("#d9534f");
        seriesFailure.LegendText = "Number of Login Failures";
        seriesFailure.IsValueShownAsLabel = true;
        seriesFailure.Font = new Font("Microsoft Sans Serif", 11);
        seriesFailure.SmartLabelStyle.Enabled = false;

        ChartMonth.Series["SeriesFailure"].Points.DataBindXY(month, monthFailure);

        Series seriesPW = ChartMonth.Series.Add("SeriesChangePW");
        seriesPW.Color = ColorTranslator.FromHtml("#5bc0de");
        seriesPW.LegendText = "Number of Password Changes";
        seriesPW.IsValueShownAsLabel = true;
        seriesPW.Font = new Font("Microsoft Sans Serif", 11);
        seriesPW.SmartLabelStyle.Enabled = false;

        ChartMonth.Series["SeriesChangePW"].Points.DataBindXY(month, monthPW);

结果,

Picture

为什么所有月份都没有显示..? 请欣赏任何帮助,谢谢!

1 个答案:

答案 0 :(得分:1)

我通过在客户端的Axis X标记中添加 Axis X Interval = 1来修复它。

                                    <asp:Chart runat="server" ID="ChartMonth" Width="1100px" Height="538px">
                                        <ChartAreas>
                                            <asp:ChartArea Name="ChartAreaMonth">
                                                <AxisX Title="Month of Year" Interval="1">
                                                    <MajorGrid Enabled="false" />
                                                </AxisX>
                                                <AxisY Title="Number of Executes">
                                                    <MajorGrid Enabled="true" />
                                                </AxisY>
                                            </asp:ChartArea>     
                                        </ChartAreas>
                                        <Legends>
                                            <asp:Legend Docking="Bottom" Name="LegendMonth"></asp:Legend>
                                        </Legends>
                                        <Titles>
                                            <asp:Title Name="TitleChart" Font="Microsoft Sans Serif, 13pt" Text="Monthly Statistics" Alignment="TopCenter"></asp:Title>
                                        </Titles>
                                    </asp:Chart>

我真的还是想知道为什么我系列中的所有X轴都没有显示出来......请随意给出答案..谢谢