Page 1 of 1
WebChart .Net Question
Posted: Fri Sep 12, 2008 5:26 pm
by 9639720
Hi,
We are trying to figure out a way to set up a WebChart in .NET to only display a Line when there is data and not draw a line to zero when there is no data.
Here is what we have now:
http://bwing.engr.colostate.edu/Arkansa ... erage%20EC
As you can see, wherever the data stops, it draws a line to zero. Is there anyway it can just stop right where it is and pick up again later when there is data?
Thanks!
Joy
Posted: Mon Sep 15, 2008 7:43 am
by narcis
Hi Joy,
Yes, you can use TreatNulls property for that as shown in the All Features\Welcome !\New in Series\Line/Horizontal line TreatNulls example at the features demo, available at TeeChart's program group.
Posted: Mon Sep 15, 2008 6:00 pm
by 9639720
Hi,
Which version of TeeChart is that in? Because I can't find it in my version - it's TeeChart vs.2
Posted: Tue Sep 16, 2008 7:19 am
by narcis
Hi Joy,
That's version 3. In v2 you can use IgnoreNulls property as shown in the example at All Features\Welcome !\Chart styles\Standard\Fast Line\Nulls and stairs in the features demo, available at TeeChart's program group.
Posted: Tue Sep 16, 2008 6:31 pm
by 9639720
Thank you very much but after going over that example I'm still unable to get it to work and I'm not sure what I'm doing wrong. If you have a moment, could you glance over this code and let me know if I'm doing something wrong?
Basically I'm looping through a dataset from a database and I'm adding the values to the fastLine as I go and then I'm looping through the dataset again a second time to set the Null values. For some reason, unless I do this in two steps the graph data shows up incorrectly. And then I set the IgnoreNulls property to true but it does the exact same thing as before - it draws a line to zero. Any help would be greatly appreciated!
Thank you!
Dim Chart1 As Steema.TeeChart.Chart = WebChart1.Chart
Chart1.Legend.CheckBoxes = True
Chart1.Aspect.View3D = False
Dim fastLine As Steema.TeeChart.Styles.FastLine = New Steema.TeeChart.Styles.FastLine(WebChart1.Chart)
For i = 0 To oDS2.Tables(0).Rows.Count - 1
For j = 1 To oDS2.Tables(0).Columns.Count - 1
If oDS2.Tables(0).Columns(j).DataType.Name <> "DateTime" Then
If IsNumeric(oDS2.Tables(0).Rows(i).Item(j)) = True Then
fastLine.Add(CType(oDS2.Tables(0).Rows(i).Item("Measurement_Date"), Date), CType(oDS2.Tables(0).Rows(i).Item(j), Double))
Else
fastLine.Add(CType(oDS2.Tables(0).Rows(i).Item("Measurement_Date"), Date), CType(0, Double))
End If
End If
Next
Next
For i = 0 To oDS2.Tables(0).Rows.Count - 1
For j = 1 To oDS2.Tables(0).Columns.Count - 1
If oDS2.Tables(0).Columns(j).DataType.Name <> "DateTime" Then
If IsDBNull(oDS2.Tables(0).Rows(i).Item(j)) Then
fastLine.SetNull(i, True)
End If
End If
Next
Next
fastLine.IgnoreNulls = True
fastLine.Stairs = True
fastLine.Title = strColumnName
fastLine.VertAxis = Steema.TeeChart.Styles.VerticalAxis.Left
fastLine.YValues.DataMember = strColumnName
fastLine.XValues.DataMember = "Measurement Date"
fastLine.XValues.DateTime = True
Chart1.Aspect.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
Chart1.Aspect.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit
Chart1.Series.Add(fastLine)
Chart1.Header.Text = Title
Chart1.Axes.Left.Labels.Text = strColumnName
Chart1.Axes.Bottom.Labels.Text = "Dates"
Posted: Tue Sep 16, 2008 7:24 pm
by 9639720
Correction: in the previous post I incorrectly wrote one statement.
"fastLine.IgnoreNulls = True" should be "fastLine.IgnoreNulls = False" Although interestingly it does the same thing regardless of what this property is set to.
Posted: Wed Sep 17, 2008 8:39 am
by narcis
Hi Joy,
Thanks for the information but I'm not able to see anything wrong with your code at first glance. Would you be so kind to arrange a simple example project we can run "as-is" to reproduce the problem here?
You can either post your files at news://
www.steema.net/steema.public.attachments newsgroup or at our
upload page.
Thanks in advance.
Posted: Wed Sep 17, 2008 6:45 pm
by 9639720
Hi,
I have prepared an ASP.NET application for you called TestGraph and uploaded it to your server demonstrating the problem we are having. When I run this example, I get the same results as my other application.
After playing with it a lot yesterday after writing you, I was able to get the graph to show some of the gaps - however, at the end of the data there are a lot of nulls in a row and for some reason the project shows it as a line even though earlier on in the series it works just fine. I stepped through my code to make sure I was really setting those points to null and not something else and as far as I can tell it's set up correctly in the code.
I've also downloaded all the updates for TeeChart vs.2 although I wasn't sure if the TeeChart.dlls were automatically updated or if I needed to go in and change that somewhere.
I guess that's about it - any help you can provide would be greatly appreciated. Thanks!
Joy
Posted: Thu Sep 18, 2008 10:43 am
by narcis
Hi Joy,
Thanks for the example project.
The main problem is that when checking if a point should be null or not you are not adding it to the chart, therefore SetNull sets the wrong point to null and moreover, the series doesn't have all data points and existing points are set to null when they shouldn't. Below there's the code I used for getting your example to work.
Code: Select all
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim sr As StreamReader = New StreamReader(Request.MapPath("ArkansasValleyData.txt"))
Dim Title, LegendTitle, strColumnName As String
Dim m_tbl As DataTable = New DataTable("DebugTable")
Dim m_row As DataRow
Dim m_Array() As String
Dim line As String
Dim i As Integer
Try
line = sr.ReadLine()
m_tbl.Columns.Add("Date").DataType = GetType(System.DateTime)
m_tbl.Columns.Add("Value").DataType = GetType(System.Double)
line = sr.ReadLine()
While Not line = ""
m_Array = Split(line, vbTab)
m_row = m_tbl.NewRow()
m_row(0) = m_Array(1)
If m_Array.Length >= 3 Then
If m_Array(2) = Nothing Then
m_row(1) = System.DBNull.Value
Else
m_row(1) = m_Array(2)
End If
Else
m_row(1) = System.DBNull.Value
End If
m_tbl.Rows.Add(m_row)
line = sr.ReadLine()
Dim Chart1 As Steema.TeeChart.Chart = WebChart1.Chart
Chart1.Legend.Visible = False
Chart1.Aspect.View3D = False
Dim fastLine1 As Steema.TeeChart.Styles.FastLine = New Steema.TeeChart.Styles.FastLine(WebChart1.Chart)
fastLine1.VertAxis = Steema.TeeChart.Styles.VerticalAxis.Left
Title = "Well #303, Study Region, Arkansas River Valley"
strColumnName = "Water Table Depth (m)"
LegendTitle = "Water Table Depth"
For i = 0 To m_tbl.Rows.Count - 1
If IsNumeric(m_tbl.Rows(i).Item(1)) Then
fastLine1.Add(CType(m_tbl.Rows(i).Item("Date"), Date), CType(m_tbl.Rows(i).Item(1), Double))
Else
fastLine1.Add(CType(m_tbl.Rows(i).Item("Date"), Date), 0)
fastLine1.SetNull(i)
End If
Next
fastLine1.Title = strColumnName
'fastLine1.YValues.DataMember = strColumnName
'fastLine1.XValues.DataMember = "Measurement Date"
fastLine1.XValues.DateTime = True
Chart1.Header.Text = Title
'Chart1.Axes.Left.Labels.Text = strColumnName
Chart1.Axes.Bottom.Labels.Text = "Dates"
fastLine1.IgnoreNulls = False
fastLine1.Stairs = True
Chart1.Axes.Bottom.Automatic = True
Chart1.Axes.Left.Automatic = True
Chart1.Axes.Left.MinimumOffset = 50
Chart1.Axes.Left.MaximumOffset = 50
End While
Catch oex As Exception
Console.WriteLine(oex.ToString)
Finally
sr.Close()
End Try
End Sub
Posted: Thu Sep 18, 2008 4:31 pm
by 9639720
Thank you so much! That did the trick!