【问题标题】:ASP.NET with MS Chart disable the vertical line带有 MS 图表的 ASP.NET 禁用垂直线
【发布时间】:2011-01-26 09:22:09
【问题描述】:

我有一个使用 MS Chart 创建的图表,如下图所示。如您所见,垂直线与每个条形顶部的值混淆。

alt text 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>

我不希望显示垂直线,因为它与每个条形顶部的值混淆了。如何禁用垂直线?

谢谢。

【问题讨论】:

    标签: .net asp.net vb.net data-visualization mschart


    【解决方案1】:

    简单的方法:

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

    【讨论】:

      【解决方案2】:

      我不知道具体的 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。MinorGrid 可以以同样的方式隐藏。

      【讨论】:

      • 这可行,但使用 Enabled 属性禁用 MajorGrid 可能是最好的方法。
      • @arviman,在发帖时,将 Enabled 属性设置为 false 实际上并没有禁用或关闭网格线。您能否确认此行为在随后的几个月内是否已更改/已修复?
      【解决方案3】:

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

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

      【讨论】:

        【解决方案4】:

        这解决了问题。谢谢。

        下面是c#代码......

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

        【讨论】:

          【解决方案5】:

          这可以从源代码工作

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2015-07-26
            • 2011-12-24
            • 2018-01-08
            • 2021-03-03
            • 2022-01-08
            • 2011-08-27
            • 1970-01-01
            相关资源
            最近更新 更多