c#asp.net折线图-X轴标签,其中y = 0

时间:2018-10-05 15:00:03

标签: c# asp.net

如何使X轴标签显示在y = 0的位置。我有一个带有负值和正值的折线图。目前,x轴显示在图表的底部,而不是y = 0。

enter image description here

下面是到目前为止我要创建以下图形的代码。我需要尝试将X轴标签移动到图表的中间而不是底部。如果可能,负点应显示在X轴标签下方。

asp.net

            <asp:Chart ID="Chart1" runat="server" border-width="2px" Width="1200px" Height="600px" ImageType="Png" CanResize="true" CssClass="table  table-bordered table-condensed table-responsive">
            <Titles>
                <asp:Title Text="Data" Font="Microsoft Sans Serif, 12pt" ForeColor="#007bff"></asp:Title>
            </Titles>
            <Legends>
                <asp:Legend Docking="Bottom" Alignment="Center"></asp:Legend>
            </Legends>



            <ChartAreas>
                <asp:ChartArea Name="ChartArea1">
                    <AxisX Title="Date" IsMarginVisible="False" TitleFont="Microsoft Sans Serif, 10pt"  >
                        <MajorGrid Enabled="false" LineColor="LightGray" />


                    </AxisX>
                    <AxisY Title="" Minimum="-15" Maximum="10" TitleFont="Microsoft Sans Serif, 10pt" Interval="5">
                        <MajorGrid Enabled="true" LineColor="LightGray" />
                    </AxisY>
                </asp:ChartArea>

            </ChartAreas>
        </asp:Chart>

C#:

private void GetChartData()
{

//Data table created using sql procedure

    List<string> status = (from p in dt.AsEnumerable()
                           select p.Field<string>("Status")).Distinct().ToList();

    foreach (string statuses in status)
    {

        //Get the Event Label
        string[] x = (from p in dt.AsEnumerable()
                      where p.Field<string>("Status") == statuses
                      select p.Field<string>("EventLabel")).ToArray();

        //Get the Total of Orders 
        int[] y = (from p in dt.AsEnumerable()
                   where p.Field<string>("Status") == statuses
                   select p.Field<int>("Total")).ToArray();

        //Add Series to the Chart.
        Chart1.Series.Add(new Series(statuses));
        Chart1.Series[statuses].IsValueShownAsLabel = false;
        Chart1.Series[statuses].MarkerStyle = MarkerStyle.Circle;
        Chart1.Series[statuses].BorderWidth = 2;
        Chart1.Series[statuses].ChartType = SeriesChartType.Line;
        Chart1.Series[statuses].Points.DataBindXY(x, y);
    }

    Chart1.Legends[0].Enabled = true;

}

1 个答案:

答案 0 :(得分:0)

                                                     

在AxisY标签中设置Crossing = 0,即可解决该问题