Page 1 of 1

Time Axis Problem

Posted: Mon Aug 07, 2006 12:02 pm
by 9078681
Hello,

We are using TeeChart.Lite for .NET v1 (Build 1.0.1224.38244) and had a question.

When our chart shows multiple instances of the same hour (for example: 7:00PM, 7:15PM, 7:30PM, 7:45PM) it does not show the minutes. Instead it shows: 7PM, 7PM, 7PM, 7PM

How can we force TeeChart to display the minutes in this case?

Posted: Mon Aug 07, 2006 1:38 pm
by Chris
Hello,

Which overload of the Series.Add method are you using to add data to your chart?

If you are adding data in as a DateTime instance and you're not adding in labels then you should be able to define the datetime format using the Steema.TeeChart.AxisLabels.DateTimeFormat Property (see tchart help for details).

Time Axis Problem

Posted: Tue Aug 08, 2006 5:30 am
by 9078681
Thanks for the help in advance.

Below is the code that I am using to show time in 15 minutes scale and it is not working, what am i doing wrong?

Line 1- chtTrades.Axes.Bottom.Increment = Steema.TeeChart.Utils.DateTimeStep(Steema.TeeChart.DateTimeSteps.FifteenMinutes)

Line 2- chtTrades.Axes.Bottom.Labels.DateTimeFormat = "h:mtt"

Now on line 2 if i make the format as it is like "h:mtt" then it shows the exact minute like 7:21 or 7:09 or 7:32, and if i use the format as " htt" it shows hours 7PM, 7PM, 7PM, 7PM.

so the real question is how can we show the time in 15 minutes increments within the same hour? is there any method or property available or do we need to format it by ourself?

Best Regards

Posted: Tue Aug 08, 2006 9:08 am
by Chris
Hello,

The following code works ok here:

Code: Select all

   private void InitializeChart()
    {
      line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
      
      DateTime now = DateTime.Now;
      Random rnd = new Random();
      int length = 90;
      for (int i = 0; i < length; i++)
      {
        now = now.AddMinutes(1);
        line1.Add(now, rnd.NextDouble());
      }
      tChart1.Axes.Bottom.Labels.DateTimeFormat = "yyyy.MM.dd HH:mm:ss";
      tChart1.Axes.Bottom.Labels.MultiLine = true;
      tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.FifteenMinutes);
    }

Time Axis Problem

Posted: Wed Aug 09, 2006 1:17 pm
by 9078681
Hi,

Thanks for the reply but it did'nt solved my problem, what i asked is
"How can i hardcode the time format in 15 Minutes interval"?

Your code above made it in real 15 minutes interval like if the current time is 17:05, it made the axis as 17:05, 17:20, 17:35, 17:50

But i was looking for something which can show the time in exact 15 minutes interval from 0 like if the current time is 17:05, it should show as 17:00, 17:15, 17:30, 17:45.

I hope i made my self clear, Thanks for helping on this.

Kind regards

Posted: Thu Aug 10, 2006 4:13 pm
by 9078681
Hi Chris, Just wondering if you saw the above message. Thanks...

Posted: Thu Aug 10, 2006 4:48 pm
by Chris
Hello,

Sure. How about trying something similar to:

Code: Select all

    private void InitializeChart()
    {
      int length = 60;
      DateTime now = DateTime.Now;
      Random rnd = new Random();
      for (int i = 0; i < length; i++)
      {
        line1.Add(now, rnd.NextDouble());
        now = now.AddMinutes(1);
      }
    }

    private bool first = true;
    private DateTime newDate;

    private void tChart1_GetNextAxisLabel(object sender, Steema.TeeChart.GetNextAxisLabelEventArgs e)
    {
      if ((sender as Steema.TeeChart.Axis).Equals(tChart1.Axes.Bottom))
      {
        e.Stop = false;

        if (first)
        {
          double value = e.LabelValue;
          DateTime date = DateTime.FromOADate(value);
          newDate = new DateTime(date.Year, date.Month, date.Day, date.Hour, 0, 0);
          if (date.Minute >= 15)
          {
            newDate = newDate.AddMinutes(15);
          }
          else if (date.Minute >= 30)
          {
            newDate = newDate.AddMinutes(30);
          }
          else if (date.Minute >= 45)
          {
            newDate = newDate.AddMinutes(45);
          }
          first = false;
        }
        else
        {
          newDate = newDate.AddMinutes(15);
        }

        switch (e.LabelIndex)
        {
          case 0:
            e.LabelValue = newDate.ToOADate();
            break;
          case 1:
            e.LabelValue = newDate.ToOADate();
            break;
          case 2:
            e.LabelValue = newDate.ToOADate();
            break;
          case 3:
            e.LabelValue = newDate.ToOADate();
            break;
          case 4:
            e.LabelValue = newDate.ToOADate();
            break;
          case 5:
            e.LabelValue = newDate.ToOADate();
            break;
          case 6:
            e.LabelValue = newDate.ToOADate();
            break;
          default:
            e.Stop = true;
            first = true;
            break;
        }
      }
    }

Axis Problem

Posted: Tue Aug 15, 2006 11:47 am
by 9078681
Hi,

No, when i used this code it showed big Red Cross (X) on the form. I am using VB.Net and i convertd the code from C# to VB.Net may be thats a problme, can you please have a look on the below code.



Private Sub InitializeChart()
Dim length As Integer = 60
Dim now As DateTime = DateTime.Now
Dim rnd As New Random
Dim i As Integer
For i = 0 To length - 1
line1.Add(now, rnd.NextDouble())
now = now.AddMinutes(1)
Next i
End Sub 'InitializeChart

Private first As Boolean = True
Private newDate As DateTime

Private Sub chtTrades_GetNextAxisLabel(ByVal sender As Object, ByVal e As Steema.TeeChart.GetNextAxisLabelEventArgs) Handles chtTrades.GetNextAxisLabel ' this bold area was not in your code
If CType(sender, Steema.TeeChart.Axis).Equals(chtTrades.Axes.Bottom) Then
e.Stop = False

If first Then
Dim value As Double = e.LabelValue
Dim [date] As DateTime = DateTime.FromOADate(value)
newDate = New DateTime([date].Year, [date].Month, [date].Day, [date].Hour, 0, 0)
If [date].Minute >= 15 Then
newDate = newDate.AddMinutes(15)
Else
If [date].Minute >= 30 Then
newDate = newDate.AddMinutes(30)
Else
If [date].Minute >= 45 Then
newDate = newDate.AddMinutes(45)
End If
End If
End If
first = False
Else
newDate = newDate.AddMinutes(15)
End If

Select Case e.LabelIndex
Case 0
e.LabelValue = newDate.ToOADate()
Case 1
e.LabelValue = newDate.ToOADate()
Case 2
e.LabelValue = newDate.ToOADate()
Case 3
e.LabelValue = newDate.ToOADate()
Case 4
e.LabelValue = newDate.ToOADate()
Case 5
e.LabelValue = newDate.ToOADate()
Case 6
e.LabelValue = newDate.ToOADate()
Case Else
e.Stop = True
first = True
End Select
End If
End Sub

Regards,

Posted: Wed Aug 16, 2006 3:01 am
by 9078681
Hi Chris, Did you get my reply (above)? Thanks...

Posted: Wed Aug 16, 2006 9:48 am
by Chris
Hello,

It works fine here:

Code: Select all

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim ch1 As Steema.TeeChart.Chart = WebChart1.Chart
        Dim tempChart As System.IO.MemoryStream = New System.IO.MemoryStream
        If Not IsPostBack Then
            InitializeChart()
        Else
            If Not Session("Chart_1") Is Nothing Then
                tempChart = DirectCast(Session("Chart_1"), System.IO.MemoryStream)
                tempChart.Position = 0
                ch1.Import.Template.Load(tempChart)

            End If
        End If
    End Sub


    Private line1 As Steema.TeeChart.Styles.Line

    Private Sub InitializeChart()
        Dim ch1 As Steema.TeeChart.Chart = WebChart1.Chart
        Dim tempChart As System.IO.MemoryStream = New System.IO.MemoryStream
        Dim length As Integer = 60
        Dim now As DateTime = DateTime.Now
        Dim rnd As New Random
        Dim i As Integer
        line1 = New Steema.TeeChart.Styles.Line(ch1)
        For i = 0 To length - 1
            line1.Add(now, rnd.NextDouble())
            now = now.AddMinutes(1)
        Next i

        ch1.Export.Template.Save(tempChart)
        Session.Add("Chart_1", tempChart)
    End Sub

    Private first As Boolean = True
    Private newDate As DateTime

    Protected Sub WebChart1_GetNextAxisLabel(ByVal sender As Object, ByVal e As Steema.TeeChart.GetNextAxisLabelEventArgs) Handles WebChart1.GetNextAxisLabel
        If CType(sender, Steema.TeeChart.Axis).Equals(WebChart1.Chart.Axes.Bottom) Then
            e.Stop = False

            If first Then
                Dim value As Double = e.LabelValue
                Dim [date] As DateTime = DateTime.FromOADate(value)
                newDate = New DateTime([date].Year, [date].Month, [date].Day, [date].Hour, 0, 0)
                If [date].Minute >= 15 Then
                    newDate = newDate.AddMinutes(15)
                Else
                    If [date].Minute >= 30 Then
                        newDate = newDate.AddMinutes(30)
                    Else
                        If [date].Minute >= 45 Then
                            newDate = newDate.AddMinutes(45)
                        End If
                    End If
                End If
                first = False
            Else
                newDate = newDate.AddMinutes(15)
            End If

            Select Case e.LabelIndex
                Case 0
                    e.LabelValue = newDate.ToOADate()
                Case 1
                    e.LabelValue = newDate.ToOADate()
                Case 2
                    e.LabelValue = newDate.ToOADate()
                Case 3
                    e.LabelValue = newDate.ToOADate()
                Case 4
                    e.LabelValue = newDate.ToOADate()
                Case 5
                    e.LabelValue = newDate.ToOADate()
                Case 6
                    e.LabelValue = newDate.ToOADate()
                Case Else
                    e.Stop = True
                    first = True
            End Select
        End If
    End Sub

Axis Problem

Posted: Wed Aug 16, 2006 1:20 pm
by 9078681
Hi,

I am sorry, but is this not a web based ASP.net coding? as i can see page load function and Session objects?, can i please get a windows forms based functions which i can incorporate in my application or do i need to re code this logic?

Regards

Posted: Wed Aug 16, 2006 2:25 pm
by Chris
Hello,

Ah, my fault, when you said big red cross I thought you were working in ASP.NET.

The code I originally sent you was for winforms.

Axis Problem

Posted: Thu Aug 17, 2006 1:21 pm
by 9078681
Hi,

http://img218.imageshack.us/my.php?imag ... rorkg6.jpg

Could you please check the link above to see what type of the chart view i am getting because of the code below?


Private Sub InitializeChart()
Dim length As Integer = 60
Dim now As DateTime = DateTime.Now
Dim rnd As New Random
Dim i As Integer
For i = 0 To length - 1
line1.Add(now, rnd.NextDouble())
now = now.AddMinutes(1)
Next i
End Sub 'InitializeChart

Private first As Boolean = True
Private newDate As DateTime

Private Sub chtTrades_GetNextAxisLabel(ByVal sender As Object, ByVal e As Steema.TeeChart.GetNextAxisLabelEventArgs) Handles chtTrades.GetNextAxisLabel ' this bold area was not in your code
If CType(sender, Steema.TeeChart.Axis).Equals(chtTrades.Axes.Bottom) Then
e.Stop = False

If first Then
Dim value As Double = e.LabelValue
Dim [date] As DateTime = DateTime.FromOADate(value)
newDate = New DateTime([date].Year, [date].Month, [date].Day, [date].Hour, 0, 0)
If [date].Minute >= 15 Then
newDate = newDate.AddMinutes(15)
Else
If [date].Minute >= 30 Then
newDate = newDate.AddMinutes(30)
Else
If [date].Minute >= 45 Then
newDate = newDate.AddMinutes(45)
End If
End If
End If
first = False
Else
newDate = newDate.AddMinutes(15)
End If

Select Case e.LabelIndex
Case 0
e.LabelValue = newDate.ToOADate()
Case 1
e.LabelValue = newDate.ToOADate()
Case 2
e.LabelValue = newDate.ToOADate()
Case 3
e.LabelValue = newDate.ToOADate()
Case 4
e.LabelValue = newDate.ToOADate()
Case 5
e.LabelValue = newDate.ToOADate()
Case 6
e.LabelValue = newDate.ToOADate()
Case Else
e.Stop = True
first = True
End Select
End If
End Sub


this is the same code i got from you i have just converted it from C# to Vb.Net so may be during conversion i have made any mistake? what do you think?

Regards

Posted: Thu Aug 17, 2006 2:47 pm
by Chris
Hello,
this is the same code i got from you i have just converted it from C# to Vb.Net so may be during conversion i have made any mistake?
Maybe you should have used one of the online C# to VB.NET converters that are out there. I did <g> ... this is the one I used:
http://www.developerfusion.co.uk/utilit ... ptovb.aspx
what do you think?
<snip>

Here's the working code in VB.NET:

Code: Select all

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        InitializeChart()
    End Sub

    Private Sub InitializeChart()
        Dim length As Integer = 60
        Dim now As DateTime = DateTime.Now
        Dim rnd As Random = New Random
        Dim i As Integer = 0
        While i < length
            Line1.Add(now, rnd.NextDouble)
            now = now.AddMinutes(1)
            System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1)
        End While
    End Sub

    Private first As Boolean = True
    Private newDate As DateTime

    Private Sub TChart1_GetNextAxisLabel(ByVal sender As Object, ByVal e As Steema.TeeChart.GetNextAxisLabelEventArgs) Handles TChart1.GetNextAxisLabel
        If DirectCast(sender, Steema.TeeChart.Axis).Equals(TChart1.Axes.Bottom) Then
            e.Stop = False
            If first Then
                Dim value As Double = e.LabelValue
                Dim aDate As DateTime = DateTime.FromOADate(value)
                newDate = New DateTime(aDate.Year, aDate.Month, aDate.Day, aDate.Hour, 0, 0)
                If aDate.Minute >= 15 Then
                    newDate = newDate.AddMinutes(15)
                Else
                    If aDate.Minute >= 30 Then
                        newDate = newDate.AddMinutes(30)
                    Else
                        If aDate.Minute >= 45 Then
                            newDate = newDate.AddMinutes(45)
                        End If
                    End If
                End If
                first = False
            Else
                newDate = newDate.AddMinutes(15)
            End If
            Select Case e.LabelIndex
                Case 0
                    e.LabelValue = newDate.ToOADate
                    ' break
                Case 1
                    e.LabelValue = newDate.ToOADate
                    ' break
                Case 2
                    e.LabelValue = newDate.ToOADate
                    ' break
                Case 3
                    e.LabelValue = newDate.ToOADate
                    ' break
                Case 4
                    e.LabelValue = newDate.ToOADate
                    ' break
                Case 5
                    e.LabelValue = newDate.ToOADate
                    ' break
                Case 6
                    e.LabelValue = newDate.ToOADate
                    ' break
                Case Else
                    e.Stop = True
                    first = True
                    ' break
            End Select
        End If
    End Sub
End Class