Avatar of rckrch
Flag for United States of America asked on

Empty Point in Chart plots 0

I have the below ASP code.  The chart now plots '0' when for an empty data point in the table.  How I make the chart show no plotted point for that reading?  I have tried to use EmptyPointStyle - does not work.

Thanks in advance for the help.

ASP Code:

<asp:Chart ID="FailStatusChart" runat="server">
                            <asp:Series Name="Series1" Color="#CC3300">
                            <EmptyPointStyle BackImageTransparentColor="Transparent"
                                LabelForeColor="Transparent" />
                            <asp:ChartArea Name="ChartArea1">
ASP.NETVisual Basic.NET.NET ProgrammingWeb Languages and StandardsWeb Development

Avatar of undefined
Last Comment

8/22/2022 - Mon
Robert Schutt

Maybe this is not a clean method but by putting this in the Page_Load I got the result I think you're looking for.
        With FailStatusChart.Series("Series1")
            For i As Integer = .Points.Count - 1 To 0 Step -1
                If .Points(i).YValues(0) = 0 Then .Points.RemoveAt(i)
        End With

Open in new window

I actually expected the point to disappear but it is shown as an empty value now which, if I'm not mistaken, is what you wanted?

Thanks Robert,

Sorry it took me so ling to get back to you on this.  Your solution is fine for a column or bar graph, but I am looking for the this effect on a line graph.  I am trying to use PostPaint to paint over the line in the graph, but not having any luck at this point.

Robert Schutt

Ah, you mean like just put a big white rectangle over it? Could you post a picture of how you want it?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Robert Schutt

Some googling around got me this, not very pretty, maybe get it to leave the gridlines alone and it should be a lot better. But without knowing what you're looking at hard to guess if this is what you need. Apart from the earlier code I added:
<asp:Chart ID="FailStatusChart" runat="server" OnPostPaint="RemoveEmpty">

Open in new window

code behind:
    Sub RemoveEmpty(ByVal sender As Object, ByVal e As ChartPaintEventArgs)
            Dim ch As Chart = sender
            Dim s As Series = e.ChartElement
            Dim px As Single = 0, x1 As Single, x2 As Single, y1 As Single, y2 As Single, ww As Single, h As Single
            Dim c0x As Axis = ch.ChartAreas(0).AxisX
            Dim c0y As Axis = ch.ChartAreas(0).AxisY
            x1 = c0x.ValueToPixelPosition(c0x.Minimum)
            x2 = c0x.ValueToPixelPosition(c0x.Maximum)
            ww = (x2 - x1) / (c0x.Maximum - c0x.Minimum)
            y1 = c0y.ValueToPixelPosition(c0y.Maximum)
            y2 = c0y.ValueToPixelPosition(c0y.Minimum)
            h = y2 - y1
            With e.ChartGraphics.Graphics
                Dim x As Single, xr As Single
                For Each p In s.Points
                    If p.XValue > px + 1 Then
                        x = c0x.ValueToPixelPosition(px + 1)
                        xr = c0x.ValueToPixelPosition(p.XValue - 1)
                        .FillRectangle(New SolidBrush(e.Chart.BackColor), x - ww / 2, y1, xr - x + ww, h - 1)
                    End If
                    px = p.XValue
            End With
        Catch ex As Exception
            ' ...
        End Try
    End Sub

Open in new window

capture 2

Thanks Robert, but this is not quite what I am looking for.  Is there not a way in asp.net or vb code behind to repaint the color of lines between 2 points in a series?  There must be a way to do that.

Thanks for the help.

Chart image
Did you get this image I sent earlier?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.

The chart image with no line plotted between points (or transparent) is what I am looking for.
Robert Schutt

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

The IsEmpty command works.  Now I am getting the effect I want.  I did not realize that the IsEmpty command had to be used for each point that is empty.  Declare the point as empty.