ASP.NET与MS Chart如何禁用垂直线?

9

我用微软图表创建了一个图形,就像下面的图片一样。正如您所看到的,每个条形顶部的值与垂直线混在了一起。

alt文本 http://img46.imageshack.us/img46/3720/chartimgaxd.png

以下是图表的标记:

        <asp:Chart ID="chtNBAChampionships" runat="server">
   <Series>
      <asp:Series Name="Championships" YValueType="Int32"  ChartType="Column" ChartArea="MainChartArea" IsValueShownAsLabel="true">
         <Points>
            <asp:DataPoint AxisLabel="Celtics" YValues="17" />
            <asp:DataPoint AxisLabel="Lakers" YValues="15" />
            <asp:DataPoint AxisLabel="Bulls" YValues="6" />
            <asp:DataPoint AxisLabel="Spurs" YValues="4" />
            <asp:DataPoint AxisLabel="76ers" YValues="3" />
            <asp:DataPoint AxisLabel="Pistons" YValues="3" />
            <asp:DataPoint AxisLabel="Warriors" YValues="3" />

         </Points>
      </asp:Series>
   </Series>
   <ChartAreas>
      <asp:ChartArea Name="MainChartArea">
      </asp:ChartArea>
   </ChartAreas>
</asp:Chart>

我不想显示竖线,因为它会与每个柱形上面的值混在一起。如何禁用这个竖线?

谢谢。

5个回答

14

简单的方法:

Chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;

7

我不知道具体的ASP语法,但以下是可以解决问题的VB.NET代码:

Dim gd As New System.Windows.Forms.DataVisualization.Charting.Grid
gd.LineWidth = 0

myChart.ChartAreas("MainChartArea").AxisX.MajorGrid = gd

如果需要,可以使用C#版本:
System.Web.UI.DataVisualization.Charting.Grid gd = new System.Web.UI.DataVisualization.Charting.Grid(); 
gd.LineWidth = 0; 

myChart.ChartAreas[0].AxisX.MajorGrid = gd;

正如您所看到的,您不能仅仅关闭网格线,您必须将其宽度设置为0。较小的网格线也可以通过相同的方式隐藏。


1
这样做是可行的,但是使用“Enabled”属性禁用MajorGrid可能是最好的方法。 - arviman
@arviman,在发布时,将Enabled属性设置为false实际上并没有禁用或关闭网格线。您能否确认这种行为在过去的几个月中是否改变/修复? - Stewbob

1

问题已解决。谢谢。

以下是C#代码....

var gd = new System.Web.UI.DataVisualization.Charting.Grid();
gd.LineWidth = 0;
Chart1.ChartAreas[0].AxisX.MajorGrid = gd;

1

最简单的方法是,在图表加载事件中放置以下代码。

protected void Chart1_Load(object sender, EventArgs e)
{
    Chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
    Chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = false;

}

0

这可以从源代码中工作

<ChartAreas>
     <asp:ChartArea Name="ChartArea1">
         <AxisX>
              <MajorGrid LineWidth="0" />
         </AxisX>
     </asp:ChartArea>
</ChartAreas>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接