Example for AxisBreaksTool?

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Wolfgang
Newbie
Newbie
Posts: 5
Joined: Tue Oct 11, 2011 12:00 am

Example for AxisBreaksTool?

Post by Wolfgang » Wed Nov 09, 2011 11:13 am

Hi,

Do you have an example how to use the AxisBreaksTool (VB preferred)?
In the Tutorials all tools are described with sourcecode except this one. Now I need the AxisBreaksTool and don’t get it running.

My X-Axis (bottom) has DateTime values. I try to display a candle-series, which has time-gaps (Weekends) and thought that the AxisBreaksTool is the right tool for it. So I added an AxisBreaksTool to the Chart-Tools-Collection, set the Axis to the Bottom-Axis and filled the Breaks collection of the AxisBreaksTool with AxisBreak–objects. When I try to fill the StartValue property of the AxisBreak with some data (Double), I get an exception of the type "System.NullReferenceException" occurred in TeeChart.dll. Because of the Date-values of the Bottom axis I tried the Double – format of the Date which is returned by the .ToOADate function of the Date-values. Don’t know if this is right. A nice example of the using of the AxisBreaksTool would be very helpful.

Thank you,
Wolfgang

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Example for AxisBreaksTool?

Post by Sandra » Wed Nov 09, 2011 4:11 pm

Hello Wolfgang,

I recommend you take a look in next lines of code where I have used AxisBreaks in Chart that have a Candle Series:

Code: Select all

        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            //InitializeChart.
            tChart1.Series.Clear();
            Steema.TeeChart.Styles.Candle candle1 = new Steema.TeeChart.Styles.Candle(tChart1.Chart);
            Random rnd = new Random(); 
            DateTime today = DateTime.Today; 
            candle1.XValues.DateTime = true;
            candle1.DateTimeFormat = "dd/MM/yyy";

            candle1.FillSampleValues(20);
         

            //AxesBreaks. 
            Steema.TeeChart.Tools.AxisBreaksTool axisbreak = new Steema.TeeChart.Tools.AxisBreaksTool(tChart1.Chart);
            Steema.TeeChart.Tools.AxisBreak axisBreak1 = new Steema.TeeChart.Tools.AxisBreak(axisbreak);
            Steema.TeeChart.Tools.AxisBreak axisBreak2 = new Steema.TeeChart.Tools.AxisBreak(axisbreak);
            axisBreak1.StartValue = DateTime.Today.AddDays(30).ToOADate(); 
            axisBreak1.EndValue = DateTime.Today.AddDays(35).ToOADate(); 
            axisBreak2.StartValue = DateTime.Today.AddDays(10).ToOADate();
            axisBreak2.EndValue = DateTime.Today.AddDays(15).ToOADate();
            axisbreak.Axis = tChart1.Axes.Bottom;
            tChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/MM/yyyy";
            axisbreak.GapSize = 20;
            tChart1.Axes.Bottom.Labels.Angle = 90;
          }
Can you tell us if previous lines of code works as you expect?

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Wolfgang
Newbie
Newbie
Posts: 5
Joined: Tue Oct 11, 2011 12:00 am

Re: Example for AxisBreaksTool?

Post by Wolfgang » Fri Nov 11, 2011 11:04 am

Hi Sandra,

thanks a lot for your code. It works perfect.

I had something very similar, using real data and get heavy crashes every time I added a break on a gap.
The magic line in your code is:
tChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/MM/yyyy";

I had not set the format of the labels and got an exception from mscorlib pointing to
Steema.TeeChart.Tools.AxisBreaksTool.ChartGetAxisLabel(Object sender, GetAxisLabelEventArgs e)

If you are interested, I can supply a small project to show exactly this effect.

Thanks again,
Wolfgang

Wolfgang
Newbie
Newbie
Posts: 5
Joined: Tue Oct 11, 2011 12:00 am

Example for AxisBreaksTool: New problem

Post by Wolfgang » Fri Nov 11, 2011 9:20 pm

Hi Sandra,

the time-gaps are killed thanks to your AxisBreaksTool. But here is the next problem:
I use the zoom-feature and depending on the time-length of the x-axis after the zooming I set the labels to a new time-format.
So I have the right labelling depending on the zoom. This works great, if no AxisBreaks are present.
If AxisBreaks are present, you may not alter the format of the TChart1.Axes.Bottom.Labels.DateTimeFormat

If you set it for example from “dd/MM/yyyy” to “HH:mm”, the same crash will happen like described above.
The error is thrown inside the TeeChart.dll and I cannot catch it with a Try -Catch – EndTry in my code.
The error only occurs, if AxisBreaks are active and defined.
I can supply sourcecode if you need it to reproduce the error.

Thank you for your help,

Wolfgang

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Example for AxisBreaksTool?

Post by Sandra » Mon Nov 14, 2011 11:30 am

Hello Wolfgang,
I had not set the format of the labels and got an exception from mscorlib pointing to
Steema.TeeChart.Tools.AxisBreaksTool.ChartGetAxisLabel(Object sender, GetAxisLabelEventArgs e)

If you are interested, I can supply a small project to show exactly this effect.
Thanks for your information. Would be very helpful for us, if you can send us a simple project to reproduce this problem.
the time-gaps are killed thanks to your AxisBreaksTool. But here is the next problem:
I use the zoom-feature and depending on the time-length of the x-axis after the zooming I set the labels to a new time-format.
So I have the right labelling depending on the zoom. This works great, if no AxisBreaks are present.
If AxisBreaks are present, you may not alter the format of the TChart1.Axes.Bottom.Labels.DateTimeFormat

If you set it for example from “dd/MM/yyyy” to “HH:mm”, the same crash will happen like described above.
The error is thrown inside the TeeChart.dll and I cannot catch it with a Try -Catch – EndTry in my code.
The error only occurs, if AxisBreaks are active and defined.
I can supply sourcecode if you need it to reproduce the error.
I have made a simple code that I think can help you to achieve as you want without problems:

Code: Select all

      public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        bool boolDateTime;
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            //InitializeChart.
            tChart1.Series.Clear();
            Steema.TeeChart.Styles.Candle candle1 = new Steema.TeeChart.Styles.Candle(tChart1.Chart);
            Random rnd = new Random(); 
            DateTime today = DateTime.Today; 
            candle1.XValues.DateTime = true;
            candle1.DateTimeFormat = "dd/mm/yyyy";

            candle1.FillSampleValues(20);


            //AxesBreaks. 
            Steema.TeeChart.Tools.AxisBreaksTool axisbreak = new Steema.TeeChart.Tools.AxisBreaksTool(tChart1.Chart);
            Steema.TeeChart.Tools.AxisBreak axisBreak1 = new Steema.TeeChart.Tools.AxisBreak(axisbreak);
            Steema.TeeChart.Tools.AxisBreak axisBreak2 = new Steema.TeeChart.Tools.AxisBreak(axisbreak);
            axisBreak1.StartValue = DateTime.Today.AddDays(30).ToOADate();
            axisBreak1.EndValue = DateTime.Today.AddDays(35).ToOADate();
            axisBreak2.StartValue = DateTime.Today.AddDays(10).ToOADate();
            axisBreak2.EndValue = DateTime.Today.AddDays(15).ToOADate();
            axisbreak.Axis = tChart1.Axes.Bottom;
            tChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/mm/yyyy";
            axisbreak.GapSize = 20;
            tChart1.Axes.Bottom.Labels.Angle = 90;
            tChart1.Zoomed += new EventHandler(tChart1_Zoomed);
           
            tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
            tChart1.Draw();
            tChart1.UndoneZoom += new EventHandler(tChart1_UndoneZoom);
          
        }

        void tChart1_UndoneZoom(object sender, EventArgs e)
        {
            boolDateTime = false;
            tChart1.Refresh();
        }

        void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            if (boolDateTime)
            {
                (tChart1[0] as Steema.TeeChart.Styles.Candle).DateTimeFormat = "HH:mm";
                tChart1.Axes.Bottom.Labels.DateTimeFormat = "HH:mm";
            }
            else
            {
                (tChart1[0] as Steema.TeeChart.Styles.Candle).DateTimeFormat = "dd/mm/yyyy";
                tChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/mm/yyyy";
            }
        }

        void tChart1_Zoomed(object sender, EventArgs e)
        {
            boolDateTime = true;
            tChart1.Refresh();
           
        }

Can you tell us, if previous code works as you expected?

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Wolfgang
Newbie
Newbie
Posts: 5
Joined: Tue Oct 11, 2011 12:00 am

Sample for throwing the error

Post by Wolfgang » Mon Nov 14, 2011 2:15 pm

Hello Sandra,

I attached a zip-file with a small VB-project showing the error. Hope that helps.

Didn’t try your code for the zooming yet, but it looks not to be the solution. I don’t have the problem to find a way to label the X-Axis accordingly.
In my program this is done in the GetAxisLabel – Event and works for labeling the Bottom-Axis from Years to Milliseconds.

The problem arises, when I have AxisBreaks defined. In this case, when you set the DateTimeFormat – property of the Bottom-Axis to a new Format-String, the same error is thrown in the TeeChart.dll like shown in my little sample-project.

I will try your code soon, but so far I can see, you set the DateTimeFormat in the AfterDraw-Event, I do it in the GetAxisLabel-Event. In both cases, the DateTimeFormat is set to a new value, which produces the error…

Thank you for your help,
Wolfgang
Attachments
TChartGapTest.zip
I had to remove the TeeChart.dll because of the size-limit. But sure you have a lot of them...
(79.05 KiB) Downloaded 416 times

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Example for AxisBreaksTool?

Post by Sandra » Thu Nov 17, 2011 10:54 am

Hello Wolfgang,

Ok.I think is necessary use Axes.Bottom.Labels.DateTimeFormat if you want your axes breaks works fine. Please can you tell us, why next code doesn't solve your problem? Because, we can try to make an example that works as you expect.

Code: Select all

Private Sub InitializeChartFromSandra()

        tChart1.Aspect.View3D = False

        tChart1.Series.Clear()

        Dim candle1 As Steema.TeeChart.Styles.Candle = New Steema.TeeChart.Styles.Candle(tChart1.Chart)
        Dim rnd As Random = New Random()
        Dim today As DateTime = DateTime.Today
        candle1.XValues.DateTime = True
        candle1.DateTimeFormat = "dd/MM/yyy"

        candle1.FillSampleValues(20)

        '        //AxesBreaks. 
        Dim axisbreak As Steema.TeeChart.Tools.AxisBreaksTool = New Steema.TeeChart.Tools.AxisBreaksTool(tChart1.Chart)
        Dim axisBreak1 As Steema.TeeChart.Tools.AxisBreak = New Steema.TeeChart.Tools.AxisBreak(axisbreak)
        Dim axisBreak2 As Steema.TeeChart.Tools.AxisBreak = New Steema.TeeChart.Tools.AxisBreak(axisbreak)
        axisBreak1.StartValue = DateTime.Today.AddDays(30).ToOADate()
        axisBreak1.EndValue = DateTime.Today.AddDays(35).ToOADate()
        axisBreak2.StartValue = DateTime.Today.AddDays(10).ToOADate()
        axisBreak2.EndValue = DateTime.Today.AddDays(15).ToOADate()
        axisbreak.Axis = tChart1.Axes.Bottom
        tChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/MM/yyyy"
        axisbreak.GapSize = 20
        tChart1.Axes.Bottom.Labels.Angle = 90
        AddHandler tChart1.Zoomed, AddressOf tChart1_Zoomed
        AddHandler tChart1.AfterDraw, AddressOf tChart1_AfterDraw
        AddHandler tChart1.UndoneZoom, AddressOf tChart1_UndoneZoom

    End Sub

    Private Sub tChart1_Zoomed(ByVal sender As System.Object, ByVal e As System.EventArgs)
        boolDateTime = True
        'tChart1.Refresh()
    End Sub

    Private Sub tChart1_AfterDraw(ByVal sender As System.Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D)
        If boolDateTime Then
            TryCast(tChart1(0), Steema.TeeChart.Styles.Candle).DateTimeFormat = "hh:mm:tt"
            tChart1.Axes.Bottom.Labels.DateTimeFormat = "hh:mm:tt"
        Else
            TryCast(tChart1(0), Steema.TeeChart.Styles.Candle).DateTimeFormat = "dd/mm/yyyy"
            tChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/mm/yyyy"
        End If


    End Sub

    Private Sub tChart1_UndoneZoom(ByVal sender As System.Object, ByVal e As System.EventArgs)
        boolDateTime = False
        tChart1.Refresh()
    End Sub

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Wolfgang
Newbie
Newbie
Posts: 5
Joined: Tue Oct 11, 2011 12:00 am

Re: Example for AxisBreaksTool?

Post by Wolfgang » Mon Nov 21, 2011 8:30 am

Hi Sandra,

thanks a lot. I don't know why your code works and my code don't. But now i am able to use the AxisBreaks.

Thanks again,

Wolfgang

Post Reply