question

HemaRamachandran-9225 avatar image
0 Votes"
HemaRamachandran-9225 asked LanHuang-MSFT answered

asp.net x value


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


dotnet-aspnet-webforms
image.png (7.1 KiB)
image.png (18.2 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

LanHuang-MSFT avatar image
0 Votes"
LanHuang-MSFT answered

Hi @HemaRamachandran-9225,
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.



1.jpg (119.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.