Index outside the bounds of the array.

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
stigbert
Newbie
Newbie
Posts: 17
Joined: Mon Oct 31, 2011 12:00 am

Re: Index outside the bounds of the array.

Post by stigbert » Tue Apr 24, 2012 10:54 am

Hi Sandra,
I have tried to reproduce the zoom problem, but I can't.

Where can I find the tutorials?

Regards,
Petter

stigbert
Newbie
Newbie
Posts: 17
Joined: Mon Oct 31, 2011 12:00 am

Re: Index outside the bounds of the array.

Post by stigbert » Tue Apr 24, 2012 1:40 pm

Hi Sandra,
Never mind the tutorials, I've found them. I think that the axis is not the one I am looking for. When I double-click in the graph, I get a vertical line (related to the cursorTool?) above this vertical line is a label containing the most significant part of the OADate for that x-value. I'd like to set the label to the actual time, i.e. 12:04:00.

Regards,
stigbert / Petter

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

Re: Index outside the bounds of the array.

Post by Sandra » Tue Apr 24, 2012 2:45 pm

Hello Petter,

Ok. I have a simple code that I think can helpful you to achieve as you want:

Code: Select all

  public Form1()
        {
            InitializeComponent();
            InitializeChart();

        }
       
        private void InitializeChart()
        {
            Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            DateTime dt = DateTime.Now;
            Random rnd = new Random();
           
            for (int i = 0; i < 10; i++)
            {
                bar1.Add(dt.ToOADate(), rnd.Next(100));
                dt = dt.AddHours(1);
            }
            tChart1.Axes.Bottom.Labels.DateTimeFormat = "HH:mm:ss";
            tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.TwoHours);
            tChart1.MouseDoubleClick += new MouseEventHandler(tChart1_MouseDoubleClick);
            tChart1.UndoneZoom += new EventHandler(tChart1_UndoneZoom);

        }

        void tChart1_UndoneZoom(object sender, EventArgs e)
        {
            tChart1[0].XValues.DateTime = false;
        }

        void tChart1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            tChart1[0].XValues.DateTime = true;
            tChart1.Axes.Bottom.Labels.DateTimeFormat = "HH:mm:ss";
        }
Please can you please tell us if previous code works as you expect?

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

stigbert
Newbie
Newbie
Posts: 17
Joined: Mon Oct 31, 2011 12:00 am

Re: Index outside the bounds of the array.

Post by stigbert » Wed Apr 25, 2012 5:39 am

Hi Sandra,
I used the idea of turning on and of DateTime and setting the format of the labels of the bottom axes and it did not work. As I said in the previous post, I don't think this has to do with the axes (nor the zooming, since in this case, we do not use zooming). The problem is the setting of the label of the cursortool and it doesn't seem to be a public property.

Regards,
stigbert / Petter

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

Re: Index outside the bounds of the array.

Post by Sandra » Thu Apr 26, 2012 9:21 am

Hello Petter,

Ok. I have made a new example where I am using a cursorTool, annotationTool and DateTime values:

Code: Select all

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        private Steema.TeeChart.Styles.Line line1;
        private Steema.TeeChart.Tools.CursorTool cursorTool1;
        private Steema.TeeChart.Tools.Annotation ann;
        private double xval;
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
           
            //Tools
            cursorTool1 = new Steema.TeeChart.Tools.CursorTool(tChart1.Chart);
            cursorTool1.Style = Steema.TeeChart.Tools.CursorToolStyles.Vertical;
            cursorTool1.Pen.Style = System.Drawing.Drawing2D.DashStyle.Dash;
            cursorTool1.FollowMouse = true;
            ann = new Steema.TeeChart.Tools.Annotation(tChart1.Chart);
            ann.Shape.Pen.Visible = false;
            ann.Shape.Shadow.Visible = false;
            ann.Shape.ShapeStyle = Steema.TeeChart.Drawing.TextShapeStyle.RoundRectangle;
           //Series
            line1 = new Line(tChart1.Chart);
            line1.Pointer.Visible = true;
            DateTime dt = DateTime.Now;
            Random rnd = new Random();

            for (int i = 0; i < 10; i++)
            {
                line1.Add(dt, rnd.Next(100));
                dt = dt.AddHours(1);
            }
            //Axes
            tChart1.Axes.Bottom.Labels.DateTimeFormat = "HH:mm:ss";
            //Events
            tChart1.AfterDraw +=new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
            cursorTool1.Change +=new Steema.TeeChart.Tools.CursorChangeEventHandler(cursorTool1_Change);
            tChart1.Draw();
        }
        private double InterpolateLineSeries(Steema.TeeChart.Styles.Custom series, int firstindex, int lastindex, double xvalue)
        {
            int index;
            for (index = firstindex; index <= lastindex; index++)
            {
                if (index == -1 || series.XValues.Value[index] > xvalue) break;
            }
            // safeguard
            if (index < 1) index = 1;
            else if (index >= series.Count) index = series.Count - 1;
            // y=(y2-y1)/(x2-x1)*(x-x1)+y1
            double dx = series.XValues[index] - series.XValues[index - 1];
            double dy = series.YValues[index] - series.YValues[index - 1];
            if (dx != 0.0) return dy * (xvalue - series.XValues[index - 1]) / dx + series.YValues[index - 1];
            else return 0.0;
        }

        private double InterpolateLineSeries(Steema.TeeChart.Styles.Custom series, double xvalue)
        {
            return InterpolateLineSeries(series, series.FirstVisibleIndex, series.LastVisibleIndex, xvalue);
        }

        private void cursorTool1_Change(object sender, Steema.TeeChart.Tools.CursorChangeEventArgs e)
        {
            xval = e.XValue;
            ann.Text = "";
            for (int i = 0; i < tChart1.Series.Count; i++)
                if (tChart1.Series[i] is Steema.TeeChart.Styles.Custom)
                {
                    ann.Text += DateTime.FromOADate(e.XValue).ToString("HH:mm:ss");
                }
        }

     
        private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {

            int xs = tChart1.Axes.Bottom.CalcXPosValue(xval);
            int ys;
            g.Brush.Visible = true;
            g.Brush.Solid = true;
            for (int i = 0; i < tChart1.Series.Count; i++)

                if (tChart1.Series[i] is Steema.TeeChart.Styles.Custom)
                {
                    ys = tChart1.Series[i].GetVertAxis.CalcYPosValue(InterpolateLineSeries(tChart1.Series[i] as Steema.TeeChart.Styles.Custom, xval));
                    g.Brush.Color = tChart1.Series[i].Color;
                    g.Ellipse(new Rectangle(xs - 4, ys - 4, 8, 8));
                    ann.Top = ys;
                    ann.Left = xs;
                }
        }
    }
}
Can you tell us if previous 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

stigbert
Newbie
Newbie
Posts: 17
Joined: Mon Oct 31, 2011 12:00 am

Re: Index outside the bounds of the array.

Post by stigbert » Thu May 03, 2012 6:20 am

Hi again Sandra,

the label of the cursortool still shows the most significant part of the OADate.

Regards,
Petter

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

Re: Index outside the bounds of the array.

Post by Sandra » Thu May 03, 2012 12:14 pm

Hello Petter,

Could you tell us how you want appear the DateTimeFormat , eg: "dd/MM/yyyy HH:mm";

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

stigbert
Newbie
Newbie
Posts: 17
Joined: Mon Oct 31, 2011 12:00 am

Re: Index outside the bounds of the array.

Post by stigbert » Thu May 03, 2012 2:24 pm

Hi Sandra,

We want the label to show the time of day in the format HH:mm:ss

Regards,
Petter

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

Re: Index outside the bounds of the array.

Post by Sandra » Fri May 04, 2012 11:22 am

Hello Petter,

Using last version 4 and previous code I have attached in this thread I am get next results:
TestDate.jpg
TestDate.jpg (94.03 KiB) Viewed 10642 times
I think code works as I expect. Can you tell please what version are you using now? The problem doesn't occur in last version of TeeChartFor.Net.

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

stigbert
Newbie
Newbie
Posts: 17
Joined: Mon Oct 31, 2011 12:00 am

Re: Index outside the bounds of the array.

Post by stigbert » Fri May 04, 2012 11:46 am

Hi Sandra,

I don't see a label above the cursortool in your chart.

Regards,
Petter

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

Re: Index outside the bounds of the array.

Post by Sandra » Fri May 04, 2012 2:07 pm

Hello Petter,

OK. I have attached my project where I have added a cursor tool and an annotation tool that works as a label where its text is in DateTime format. Using this project, I have gotten the results you have seen in the image I have attached in previous post.
SendProject.zip
(19.85 KiB) Downloaded 437 times
Could you please, check my project and run it in your computer and if it doesn't works as you expect, please tell me why? So we try to change it to achieve works as you want.

On the other hand, please would be very helpful for us, if you can tell us which version are you using to make this application.

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

Post Reply