asp.net x value

Hema Ramachandran 176 Reputation points
2022-03-30T13:27:52.667+00:00

How can I hide X value label, if there is no Y value?
For example I want to hide X axis values 16 and 18

188398-image.png

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,371 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 27,796 Reputation points Microsoft Vendor
    2022-03-31T08:59:30.133+00:00

    Hi @Hema Ramachandran ,
    I think you can use an if statement to determine whether y has a value,
    if y has no value and the x point is empty, you can refer to the following example:

    <asp:Chart ID="Chart1" runat="server">  
        	<Series>  
        		<asp:Series Name="Testing" YValueType="Int32">  
        			<Points>  
        				<asp:DataPoint AxisLabel="Test 1" YValues="10" />  
        				<asp:DataPoint AxisLabel="Test 2" YValues=" " />  
        				<asp:DataPoint AxisLabel="Test 3" YValues="0" />  
        				<asp:DataPoint AxisLabel="Test 4" YValues="40" />  
        			</Points>  
        		</asp:Series>  
        	</Series>  
        	<ChartAreas>  
        		<asp:ChartArea Name="ChartArea1">  
        		</asp:ChartArea>  
        	</ChartAreas>  
        </asp:Chart>  
    

    code behind:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
            For Each series As System.Web.UI.DataVisualization.Charting.Series In Chart1.Series  
                For Each point As System.Web.UI.DataVisualization.Charting.DataPoint In series.Points  
                    If point.YValues.Length > 0 AndAlso CDbl(point.YValues.GetValue(0)) = 0 Then  
                        point.LegendText = point.AxisLabel  
                        point.AxisLabel = String.Empty  
                        point.Label = String.Empty  
                    End If  
                Next  
            Next  
    End Sub  
    

    188638-1.jpg
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments