Author |
Topic  |
|
kinetric
5 Posts |
Posted - 11 Jan 2005 : 21:08:52
|
I can not get the XAxis label to display. I have included my code. Can you please tell me what I am missing? Initially, I create a System.Data.DataSet. I then pass this to a conversion function to create a TimeSimpleDataset. I have included the conversion function. The data included in the DataSet is formatted as follows:
VALUE_DATE ITEM_VALUE 2004-05-02 00:00:03.877, 16585 2004-05-02 00:00:18.880, 16554 2004-05-02 00:00:33.880, 16580 2004-05-02 00:00:48.883, 16562 2004-05-02 00:01:03.883, 16575 2004-05-02 00:01:18.887, 16580 2004-05-02 00:01:33.887, 16570 2004-05-02 00:01:48.887, 16564 2004-05-02 00:02:03.890, 16567
The data is read every 15 seconds. I have tried several formats for the XAxis. Just hour would be fine. Perhaps Day and Hour. Eventually, this chart will refresh real-time but for now I simply need to move forward on the XAxis. Some more examples of Time Axis formatting and functionality would be helpful if documented.
Thanks
Private Function InitializeChart(ByVal chartvu As ChartView) 'Get Data in DataSet here Dim oDataGraph As New ProcessData (ConfigurationSettings.AppSettings("HydraDataSource"))
Dim oGraphUtil As New NewHydra.GraphUtil Dim ds As DataSet ds = oDataGraph.GetRawData("HRMS_STADIUM_TK_LEVEL", "5/2/2004", "5/3/2004")
Dim tds As TimeSimpleDataset tds = oGraphUtil.ConvertDataSet(ds)
Dim theFont As Font 'Create a default font theFont = New Font("Microsoft Sans Serif", 10, FontStyle.Bold) Dim pTransform1 As New TimeCoordinates 'Autoscale the coordinate system pTransform1.AutoScale(tds, ChartObj.AUTOAXES_FAR, ChartObj.AUTOAXES_FAR) 'Position plotting area in window pTransform1.SetGraphBorderDiagonal(0.25, 0.25, 0.95, 0.5)
'Simple white background Dim graphbackground1 As New Background(pTransform1, ChartObj.GRAPH_BACKGROUND, Color.White) chartvu.AddChartObject(graphbackground1)
'Simple black background for plot area Dim plotbackground As New Background(pTransform1, ChartObj.PLOT_BACKGROUND, Color.White) chartvu.AddChartObject(plotbackground)
'Create x-axis as a time axis Dim xAxis As New TimeAxis(pTransform1) xAxis.LineColor = Color.Black
'Place a major/minor tick marks xAxis.AxisTickMarkTimeBase = ChartObj.TIMEAXIS chartvu.AddChartObject(xAxis)
'Create y-axis as a linear axis Dim yAxis As New LinearAxis(pTransform1, ChartObj.Y_AXIS) yAxis.LineColor = Color.Black chartvu.AddChartObject(yAxis)
'Create the x-axis labels Dim xAxisLab As New TimeAxisLabels(xAxis) xAxisLab.AxisLabelsFormat = ChartObj.TIMEDATEFORMAT_24HM xAxisLab.LineColor = Color.Black chartvu.AddChartObject(xAxisLab)
'Create the y-axis labels Dim yAxisLab As New NumericAxisLabels(yAxis) yAxisLab.LineColor = Color.Black yAxisLab.AxisLabelsDecimalPos = 0 chartvu.AddChartObject(yAxisLab)
'Create the y-axis title Dim yAxisTitle As New AxisTitle(yAxis, theFont, "Level") yAxisTitle.LineColor = Color.Black chartvu.AddChartObject(yAxisTitle)
'Create a grid for the y-axis Dim ygrid As New Grid(xAxis, yAxis, ChartObj.Y_AXIS, ChartObj.GRID_MAJOR) ygrid.LineColor = Color.White ygrid.LineStyle = DashStyle.Solid chartvu.AddChartObject(ygrid)
Dim defaultAttrib As ChartAttribute = New ChartAttribute(Color.Blue, 1.0, DashStyle.Solid)
'Create a simple line plot using tds. Dim thePlot1 As New SimpleLinePlot(pTransform1, tds, defaultAttrib) chartvu.AddChartObject(thePlot1)
'Add a title to the graph Dim theTitleFont As New Font("Microsoft Sans Serif", 24, FontStyle.Bold) Dim mainTitle As New ChartTitle(pTransform1, theTitleFont, "Tank Level") mainTitle.TitleType = ChartObj.CHART_HEADER mainTitle.TitlePosition = ChartObj.CENTER_GRAPH mainTitle.LineColor = Color.Black chartvu.AddChartObject(mainTitle)
End Function
Public Function ConvertDataSet(ByVal ds As System.Data.DataSet) As TimeSimpleDataset
Dim i As Integer = 0 Dim DataPoints As Integer = ds.Tables(0).Rows.Count - 1 Dim YValues(DataPoints) As Double Dim XValues(DataPoints) As ChartCalendar
For i = 0 To ds.Tables(0).Rows.Count - 1 YValues(i) = CType(ds.Tables(0).Rows(i).Item("ITEM_VALUE").ToString, Double)
XValues(i) = New ChartCalendar(CType(ds.Tables(0).Rows(i).Item("VALUE_DATE").ToString, DateTime))
Next i Dim tsd As New TimeSimpleDataset("MyData", XValues, YValues) Return tsd
End Function
|
|
kinetric
5 Posts |
Posted - 11 Jan 2005 : 21:16:09
|
Not all of my code was included in previous post.
'Create x-axis as a time axis Dim xAxis As New TimeAxis(pTransform1) xAxis.LineColor = Color.Black
'Place a major/minor tick marks xAxis.AxisTickMarkTimeBase = ChartObj.TIMEAXIS chartvu.AddChartObject(xAxis)
'Create y-axis as a linear axis Dim yAxis As New LinearAxis(pTransform1, ChartObj.Y_AXIS) yAxis.LineColor = Color.Black chartvu.AddChartObject(yAxis)
'Create the x-axis labels Dim xAxisLab As New TimeAxisLabels(xAxis) xAxisLab.AxisLabelsFormat = ChartObj.TIMEDATEFORMAT_24HM xAxisLab.LineColor = Color.Black chartvu.AddChartObject(xAxisLab)
'Create the y-axis labels Dim yAxisLab As New NumericAxisLabels(yAxis) yAxisLab.LineColor = Color.Black yAxisLab.AxisLabelsDecimalPos = 0 chartvu.AddChartObject(yAxisLab)
'Create the y-axis title Dim yAxisTitle As New AxisTitle(yAxis, theFont, "Level") yAxisTitle.LineColor = Color.Black chartvu.AddChartObject(yAxisTitle)
'Create a grid for the y-axis Dim ygrid As New Grid(xAxis, yAxis, ChartObj.Y_AXIS, ChartObj.GRID_MAJOR) ygrid.LineColor = Color.White ygrid.LineStyle = DashStyle.Solid chartvu.AddChartObject(ygrid)
Dim defaultAttrib As ChartAttribute = New ChartAttribute(Color.Blue, 1.0, DashStyle.Solid) 'Create a simple line plot using tds. Dim thePlot1 As New SimpleLinePlot(pTransform1, tds, defaultAttrib) chartvu.AddChartObject(thePlot'Add a title to the graph
Dim theTitleFont As New Font("Microsoft Sans Serif", 24, FontStyle.Bold) Dim mainTitle As New ChartTitle(pTransform1, theTitleFont, "Tank Level") mainTitle.TitleType = ChartObj.CHART_HEADER mainTitle.TitlePosition = ChartObj.CENTER_GRAPH mainTitle.LineColor = Color.Black chartvu.AddChartObject(mainTitle)
Public Function ConvertDataSet(ByVal ds As System.Data.DataSet) As TimeSimpleDataset
Dim i As Integer = 0 Dim DataPoints As Integer = ds.Tables(0).Rows.Count - 1 Dim YValues(DataPoints) As Double Dim XValues(DataPoints) As ChartCalendar
For i = 0 To ds.Tables(0).Rows.Count - 1 YValues(i) = CType(ds.Tables(0).Rows(i).Item("ITEM_VALUE").ToString, Double) XValues(i) = New ChartCalendar(CType(ds.Tables(0).Rows(i).Item("VALUE_DATE").ToString, DateTime)) Next i
Dim tsd As New TimeSimpleDataset("MyData", XValues, YValues) Return tsd
End Function |
 |
|
quinncurtis
1164 Posts |
Posted - 24 Feb 2005 : 08:50:30
|
Sorry, no one noticed that this thread had never been answered.
There are 95 different examples (use Find In Files "TimeCoordinates") of using time coordinates and creating time axes in just the ChartTabDemo example program alone. The Charts of the Week also have many more examples.
The most obvious error in the program is the line:
xAxis.AxisTickMarkTimeBase = ChartObj.TIMEAXIS
The TimeAxis.AxisTickMarkTimeBase property uses constants that are of the form ChartObj.TIMEAXIS_MINUTE15SECOND.
See the TimeAxis file of the ChartTabDemo example program.
If you still cannot get the axis to display see if you can create a complete project of an example that you can send us.
|
 |
|
|
Topic  |
|
|
|