Link to home
Start Free TrialLog in
Avatar of rckrch
rckrchFlag 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">
               
                        <Series>
                            <asp:Series Name="Series1" Color="#CC3300">
                            <EmptyPointStyle BackImageTransparentColor="Transparent"
                                BackSecondaryColor="Transparent"
                                BorderColor="Transparent"
                                BorderDashStyle="NotSet"
                                Color="Transparent"
                                IsVisibleInLegend="False"
                                LabelBackColor="Transparent"
                                LabelBorderColor="Transparent"
                                LabelBorderDashStyle="NotSet"
                                LabelForeColor="Transparent" />
                            </asp:Series>
                                                       
                        </Series>
                       
                        <ChartAreas>
                            <asp:ChartArea Name="ChartArea1">
                            </asp:ChartArea>
                           
                        </ChartAreas>
                    </asp:Chart>
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

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)
            Next
        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?
User generated image
Avatar of rckrch

ASKER

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.

Thanks
Ah, you mean like just put a big white rectangle over it? Could you post a picture of how you want it?
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)
        Try
            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
                Next
            End With
        Catch ex As Exception
            ' ...
        End Try
    End Sub

Open in new window

output:
User generated image
Avatar of rckrch

ASKER

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.
Avatar of rckrch

ASKER

User generated image
Did you get this image I sent earlier?
Avatar of rckrch

ASKER

The chart image with no line plotted between points (or transparent) is what I am looking for.
ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rckrch

ASKER

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.