Cursor y Scroll

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Mel
Newbie
Newbie
Posts: 7
Joined: Mon Feb 05, 2018 12:00 am

Cursor y Scroll

Post by Mel » Mon Jul 23, 2018 8:21 pm

Hola,
Estoy programando varios TeeChart en Visual Studio 2017 con VB.NET y quiero hacer 3 cosas, que aún no logro ejecutar, espero me puedan ayudar ya que soy nueva ocupando este tipo de gráficos.

1. Mi eje X contiene fecha y hora y quiero que se vaya mostrando 1 hora cada vez y que automáticamente se vaya moviendo cuando llegue a 1 hora 1 minuto y así, pero no se como hacerlo si mi eje X no son numeros enteros si no que fechas como dije anteriormente.

2. Luego de poder realizar lo del punto 1 quisiera poder agregar unos botones en la parte inferior del gráfico para así ir retrocediendo para ver datos pasados o avanzando, según requiera.

3. Y por último quisiera pone un cursor vertical en el gráfico para poder ir visualizando los valores (ya hice para visualizar los valores, pero me sale la flecha normal de windows y quiero que sea un cursor que abarque todo el alto del TeeChart)

Muchas gracias y espero puedan ayudarme.
Saludos

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Cursor y Scroll

Post by Christopher » Tue Jul 24, 2018 9:02 am

Hola!

Para empezar, he escrito este código que produce el gif en la parte inferior. Perdone que no lo haya escrito en VB.NET - si necessita ayuda con el C# dígamelo y le haré una traducción.

Code: Select all

		public Form1()
		{

			InitializeComponent();
			InitializeChart();
		}

		private Line line;
		private void InitializeChart()
		{
			line = new Line(tChart1.Chart);
			line.XValues.DateTime = true;

			tChart1.Axes.Bottom.Labels.Angle = 90;
			tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneHour);
			tChart1.Axes.Bottom.Labels.DateTimeFormat = "yyyy/MM/dd hh:mm:ss";

			DateTime dateTime = DateTime.Now;
			Random rnd = new Random();

			for (int i = 0; i < 400; i++)
			{
				line.Add(dateTime, rnd.Next(1000));
				dateTime = dateTime.AddMinutes(15);
			}

			tChart1.Axes.Bottom.SetMinMax(line.XValues[175], line.XValues[225]);

			CursorTool cursorTool = new CursorTool(tChart1.Chart);
			cursorTool.Series = line;
			cursorTool.FollowMouse = true;
			cursorTool.Pen.Color = System.Drawing.Color.Red;
			cursorTool.Style = CursorToolStyles.Vertical;
			cursorTool.Change += CursorTool_Change;
		}

		private void CursorTool_Change(object sender, CursorChangeEventArgs e)
		{
			int start = tChart1.Axes.Left.IStartPos;
			int end = tChart1.Axes.Left.IEndPos;
			int valueIndex;

			for (int i = start; i < end; i++)
			{
				valueIndex = line.Clicked(e.x, i);
				if (valueIndex > -1)
				{
					tChart1.Header.Text = "YValue: " + line.YValues[valueIndex];
					break;
				}
			}
		}

		private void DoScrollBottomAxis(double offset, bool positive)
		{
			double max = tChart1.Axes.Bottom.Maximum;
			double min = tChart1.Axes.Bottom.Minimum;
			if (positive)
				tChart1.Axes.Bottom.SetMinMax(min + offset, max + offset);
			else
				tChart1.Axes.Bottom.SetMinMax(min - offset, max - offset);

		}

		private void bLeft_Click(object sender, EventArgs e)
		{
			DoScrollBottomAxis(Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneHour), false);
		}

		private void bRight_Click(object sender, EventArgs e)
		{
			DoScrollBottomAxis(Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneHour), true);
		}
2018-07-24_10-56-11.gif
2018-07-24_10-56-11.gif (227.53 KiB) Viewed 16230 times
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Mel
Newbie
Newbie
Posts: 7
Joined: Mon Feb 05, 2018 12:00 am

Re: Cursor y Scroll

Post by Mel » Mon Jul 30, 2018 6:45 pm

Hola Christopher,
Muchas gracias por tu ayuda es exactamente lo que quiero hacer, pero es dificil pasarlo a vb.net, ya que al parecer las clases no tienen los mismos nombres, por ejemplo eso del cursor, no se como declararlo, me podrías ayudar un poco para convertir el codigo? Gracias otra vez!!

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Cursor y Scroll

Post by Christopher » Tue Jul 31, 2018 10:18 am

Hola,

claro que sí, aquí tienes el codigo en VB.NET

Code: Select all

	Public Sub New()

		' This call is required by the designer.
		InitializeComponent()

		' Add any initialization after the InitializeComponent() call.

		InitializeChart()

	End Sub

	Private Sub bLeft_Click(sender As Object, e As EventArgs) Handles bLeft.Click
		DoScrollBottomAxis(Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneHour), False)
	End Sub

	Private Sub bRight_Click(sender As Object, e As EventArgs) Handles bRight.Click
		DoScrollBottomAxis(Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneHour), True)
	End Sub

	Dim line1 As Line

	Private Sub DoScrollBottomAxis(offset As Double, positive As Boolean)
		Dim max As Double = TChart1.Axes.Bottom.Maximum
		Dim min As Double = TChart1.Axes.Bottom.Minimum
		If positive Then
			TChart1.Axes.Bottom.SetMinMax(min + offset, max + offset)
		Else
			TChart1.Axes.Bottom.SetMinMax(min - offset, max - offset)
		End If
	End Sub

	Private Sub InitializeChart()
		line1 = New Line(TChart1.Chart)
		line1.XValues.DateTime = True

		TChart1.Axes.Bottom.Labels.Angle = 90
		TChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(DateTimeSteps.OneHour)
		TChart1.Axes.Bottom.Labels.DateTimeFormat = "yyyy/MM/dd hh:mm:ss"

		Dim dateTime As DateTime = DateTime.Now
		Dim rnd As Random = New Random()

		For i = 0 To 400
			line1.Add(dateTime, rnd.Next(1000))
			dateTime = dateTime.AddMinutes(15)
		Next

		TChart1.Axes.Bottom.SetMinMax(line1.XValues.Item(175), line1.XValues.Item(225))

		Dim cursorTool As CursorTool = New CursorTool(TChart1.Chart)
		cursorTool.Series = line1
		cursorTool.FollowMouse = True
		cursorTool.Pen.Color = Color.Red
		cursorTool.Style = CursorToolStyles.Vertical
		AddHandler cursorTool.Change, AddressOf CursorTool_Change


	End Sub

	Private Sub CursorTool_Change(sender As Object, e As CursorChangeEventArgs)
		Dim start As Integer = TChart1.Axes.Left.IStartPos
		Dim ended As Integer = TChart1.Axes.Left.IEndPos
		Dim valueIndex As Integer

		Try
			For i = start To ended
				valueIndex = line1.Clicked(e.x, i)
				If valueIndex > -1 Then
					TChart1.Header.Text = "YValue: " + line1.YValues.Item(valueIndex).ToString()
					Exit Try
				End If
			Next
		Finally
		End Try
	End Sub
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Mel
Newbie
Newbie
Posts: 7
Joined: Mon Feb 05, 2018 12:00 am

Re: Cursor y Scroll

Post by Mel » Tue Jul 31, 2018 3:26 pm

Christopher,
Muchas gracias, pero no me resulta y descubrí que no tengo el CursorTool dentro de las Tools de mi TeeChart, que podrá ser? Me podrías ayudar nuevamente, por favor? Saludos!!

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Cursor y Scroll

Post by Christopher » Wed Aug 01, 2018 7:11 am

Hola Mel,

Cual es la versión de TeeChart que utilizas? La versión Business (aquí) no tiene el CursorTool, por ejemplo.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Mel
Newbie
Newbie
Posts: 7
Joined: Mon Feb 05, 2018 12:00 am

Re: Cursor y Scroll

Post by Mel » Tue Aug 28, 2018 2:45 pm

Christopher wrote:
Wed Aug 01, 2018 7:11 am
Hola Mel,

Cual es la versión de TeeChart que utilizas? La versión Business (aquí) no tiene el CursorTool, por ejemplo.
Hola Christopher,
Era lo que decías, ahora ya actualicé mi teechart a versión pro y me aparece el cursor, pero necesito que la función CursorTool_Change sea genérica, osea yo pasarle el nombre del teechart y me vaya agregando el cursor a cada uno. Como lo podría hacer? Ya que pasarle parámetros en el add handler me pide un parametro para "cursorchangeeventargs" y no se que debo pasarle, me podrías ayudar?
Muchas gracias por todo!!

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Cursor y Scroll

Post by Christopher » Wed Aug 29, 2018 7:34 am

Hola Mel,

así con la versión Pro de TeeChart ya puedes compilar y ejecutar el código en mi mensaje aquí? Perdona, pero no entiendo muy bien qué cosas quieres hacer más con este código - me lo puedes explicar en más detalle por favor?
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Post Reply