Hello,
I'm having a strange problem with date-time data. I'm reading the data from a MySQL database and displaying it as a scatter plot. I can get the x-axis to display as numbers, but when I try to display dates, I get values in the 1900's. The actual data from the database displays properly (recent dates) in a gridview.
Here's my code...
Imports mysql.data.mysqlclient
Imports System.IO
Imports System.Data
Imports System.Windows
Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
'Create the DataTable
Dim dt As New DataTable()
Dim myConnection As New MySqlConnection("server=egr3.egr.nau.edu;uid=wis_str_datt_usr;pwd=xxxxxx;database=wisard_streamed_data_test;")
Dim strSQL As String
'get the data into a datatable
strSQL = "SELECT * FROM streamed_data WHERE ProbeID = 20 AND SensorID = 104"
Dim myAdapter As New MySqlDataAdapter()
myAdapter.SelectCommand = New MySqlCommand(strSQL, myConnection)
myAdapter.Fill(dt)
'test binding to a gridview
'dgdata.DataSource = dt
'dgdata.DataBind()
'lets make a teechart!
Dim Point1 As New Steema.TeeChart.Styles.Points(WebChart1.Chart)
WebChart1.Chart.Axes.Bottom.Labels.DateTimeFormat = "yyyy/MM/dd"
Point1.YValues.DataMember = dt.Columns("measurement").ToString()
Point1.XValues.DateTime = dt.Columns("TimeStamp").DateTimeMode
Point1.DataSource = dt
End Sub
End Class
weird datetime problem
-
- Newbie
- Posts: 24
- Joined: Wed Feb 22, 2006 12:00 am
- Location: Flagstaff, Arizona, USA
Hi LordWhorfin
The problem can be that you have got the "DATE" values defined in the data base and you don't pass the DateTime values to the chart.
Could you try with below code:
It's a C# code but if you need you can convert it to VB.NET
The problem can be that you have got the "DATE" values defined in the data base and you don't pass the DateTime values to the chart.
Could you try with below code:
Code: Select all
private DataTable CreateDataSet()
{
#region Define Table
DataTable DesperdicioMes = new DataTable();
DataColumn DATE = new DataColumn("DATE", Type.GetType("System.DateTime"));
DataColumn VALUES = new DataColumn("VALUES", Type.GetType("System.Double"));
DataColumn LABELS = new DataColumn("LABELS", Type.GetType("System.String"));
DesperdicioMes.Columns.Add(DATE);
DesperdicioMes.Columns.Add(VALUES);
DesperdicioMes.Columns.Add(LABELS);
#endregion
#region Populate Table
DataRow dataRow;
Random YVal = new Random();
dataRow = DesperdicioMes.NewRow();
dataRow[DATE] = DateTime.Parse("30/06/2007");
dataRow[VALUES] = YVal.Next();
dataRow[LABELS] = "";
DesperdicioMes.Rows.Add(dataRow);
for (int i = 1; i < 31; i++)
{
dataRow = DesperdicioMes.NewRow();
dataRow[DATE] = DateTime.Parse(i.ToString() + "/07/2007");
dataRow[VALUES] = YVal.Next();
dataRow[LABELS] = "";
DesperdicioMes.Rows.Add(dataRow);
}
dataRow = DesperdicioMes.NewRow();
dataRow[DATE] = DateTime.Parse("01/08/2007");
dataRow[VALUES] = YVal.Next();
dataRow[LABELS] = "";
DesperdicioMes.Rows.Add(dataRow);
#endregion
return DesperdicioMes;
}
private void Form1_Load(object sender, System.EventArgs e)
{
line1.XValues.DateTime = true;
tChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/MM/yyyy";
tChart1.Axes.Bottom.Labels.Angle = 90;
line1.Clear();
line1.DataSource = CreateDataSet();
line1.YValues.DataMember = "VALUES";
line1.XValues.DataMember = "DATE";
line1.LabelMember = "LABELS";
line1.CheckDataSource();
}