Hi All
I am embracing VB.Net 2010.
A far cry from Microsoft Access that I have learned to love, however the new .net Chart tool is fantastic; so many options to choose from.
An existing database has the following fields. It is a stock price chart.
Date, (Formatted as short date) Time (Formatted as time), Price (formatted as currency) in the linked table.
I would like to show time as one x axis legend above the date as it changes from day to day.
The attached codes shows the date correctly retrieved form the data file an Access MDB file. Together with the price charted above so far so good.
The problem lies with the time. I have not found a way to successfully display it as a secondary x axis.
If anyone has an answer to this question it would be most appreciated.
Thank You
I am embracing VB.Net 2010.
A far cry from Microsoft Access that I have learned to love, however the new .net Chart tool is fantastic; so many options to choose from.
An existing database has the following fields. It is a stock price chart.
Date, (Formatted as short date) Time (Formatted as time), Price (formatted as currency) in the linked table.
I would like to show time as one x axis legend above the date as it changes from day to day.
The attached codes shows the date correctly retrieved form the data file an Access MDB file. Together with the price charted above so far so good.
The problem lies with the time. I have not found a way to successfully display it as a secondary x axis.
If anyone has an answer to this question it would be most appreciated.
Thank You
Code:
Private Sub cmdLoadChart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLoadChart.Click
' The Access database
Dim fileNameString As String
fileNameString = "C:\Program Files (x86)\Deplenthion\data\ExchangeASX\ASL.mdb"
' Initialize a connection string
Dim myConnectionString As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString
' Define the database query
Dim mySelectQuery As String = "SELECT tblCotPulseData.Date, tblCotPulseData.Price FROM tblCotPulseData ORDER BY tblCotPulseData.Date, tblCotPulseData.[Seq No];"
' Create a database connection object using the connection string
Dim myConnection As New OleDbConnection(myConnectionString)
' Create a database command on the connection using query
Dim myCommand As New OleDbCommand(mySelectQuery, myConnection)
' Open the connection
myCommand.Connection.Open()
' Create a database reader
Dim myReader As OleDbDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
' Since the reader implements IEnumerable, pass the reader directly into
' the DataBind method with the name of the Column selected in the query
Chart1.Series("Series1").Points.DataBindXY(myReader, "date", myReader, "Price")
' Close the reader and the connection
myReader.Close()
myConnection.Close()
' Zoom into the X axis
Chart1.ChartAreas("ChartArea1").AxisX.ScaleView.Zoom(10, 10)
' Enable range selection and zooming end user interface
'Chart1.ChartAreas("ChartArea1").AxisX2.Enabled = AxisEnabled.True
'FIXME how do you male time show separately?
'Cursor allows you to select a range
Chart1.ChartAreas("ChartArea1").CursorX.IsUserEnabled = True
Chart1.ChartAreas("ChartArea1").CursorX.IsUserSelectionEnabled = True
'Zoom
Chart1.ChartAreas("ChartArea1").AxisX.ScaleView.Zoomable = True
Chart1.ChartAreas("ChartArea1").AxisX.ScrollBar.IsPositionedInside = False
Chart1.Series(0).XValueType = DataVisualization.Charting.ChartValueType.DateTime
End Sub