Visual CSharp .NET - Crear datos en grafica.

 
Vista:
sin imagen de perfil
Val: 9
Ha mantenido su posición en Visual CSharp .NET (en relación al último mes)
Gráfica de Visual CSharp .NET

Crear datos en grafica.

Publicado por José Luis (4 intervenciones) el 22/02/2017 16:55:03
Hola a todos,

Tengo que crear unos datos para una gráfica porque se cuida la tendencia de la gráfica de meses o días anteriores.

Estos valores los creamos manualmente a cada 5 minutos.

Pero se me ha ocurrido una idea y me gustaría saber si me pueden orientar a realizarlo.

Mi idea es la siguiente:

crear una aplicación en la cual pueda yo cargar datos de un archivo ascii y colocarlas en un recuadro.

En la cual yo pueda indicar su escala vertical (valores numericos) y escala horizontal (valor datetime).

Después con el mouse al hacer click sostenido sobre la imagen para seguir alguna linea que yo quiera, se pinte una linea de cualquier color, pero al mismo tiempo me esté generando el dato que corresponda al valor x y el valor y.

NO QUIERO QUE ME LO HAGAN, ESTOY PIDIENDO QUE ME ORIENTEN en donde puedo conseguir un código así para modificarlo.

Puede ser el cualquier otro lenguaje, pero lo quiero hacer para windows 7.


Saludos
José Luis
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 9
Ha mantenido su posición en Visual CSharp .NET (en relación al último mes)
Gráfica de Visual CSharp .NET

Crear datos en grafica.

Publicado por José Luis (4 intervenciones) el 22/02/2017 16:57:14
Encontré estos videos que me va a servir para realizar mi programa.



Me falta insertar la imagen, ajustar a la escala o definir la escala para dibujar sobre el y generar los datos al pasar el mouse pulsado, grabando en un archivo ascii para luego meterlo a una base de datos de otro servidor en linux con mongodb.


Saludos
José Luis
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 9
Ha mantenido su posición en Visual CSharp .NET (en relación al último mes)
Gráfica de Visual CSharp .NET

Crear datos en grafica.

Publicado por José Luis (4 intervenciones) el 22/02/2017 17:03:50
Hola,

He terminado mi código de manera preliminar, ahora voy a hacerlo bonito pero el esquema es el siguiente:

El programa lee un archivo ascii que contenga los siguientes datos: fecha en formato aaaa-mm-dd hh:mm:ss y el valor que se va a graficar.
El programa genera en el textbox el resultado que se usará para rellenar el dato faltante.

He utilizado la unidad pixel como unidad minuto.


Aquí les dejo el código que he utilizado.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.IO;
 
namespace paint1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Point posicionPrevia = new Point(-1, -1);
        private void canvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (posicionPrevia.X == -1)
            {
                posicionPrevia = new Point(e.X, e.Y);
            }
            Point posicionActual = new Point(e.X, e.Y);
            Graphics dibujo = canvas.CreateGraphics();
            dibujo.SmoothingMode = SmoothingMode.None;
            if (e.Button == MouseButtons.Left)
            {
                // Para permitir dibujar no debe de salirse del recuadro.
                if ((e.X >= 0 && e.X <= this.canvas.Size.Width) && (e.Y >= 0 && e.Y <= this.canvas.Height))
                {
                    dibujo.DrawLine(new Pen(Color.Blue, 2),
                    posicionPrevia, posicionActual);
                    // Grabar el dato en el textbox
                    var MyFecha_tmp = new DateTime(Convert.ToInt32(tb_FI.Text.Substring(0, 4)), Convert.ToInt32(tb_FI.Text.Substring(5, 2)), Convert.ToInt32(tb_FI.Text.Substring(8, 2)), Convert.ToInt32(tb_FI.Text.Substring(11, 2)), Convert.ToInt32(tb_FI.Text.Substring(14, 2)), 0, DateTimeKind.Utc);
                    MyFecha_tmp = MyFecha_tmp.AddMinutes(e.X);
                    decimal ymin, ymax, ydif;
                    ymin = Convert.ToDecimal(tb_ymin.Text);
                    ymax = Convert.ToDecimal(tb_ymax.Text);
                    ydif = 280 / (ymax - ymin);
                    if (posicionPrevia.X != posicionActual.X)
                    {
                        textBox1.Text = textBox1.Text + MyFecha_tmp.ToString("yyyy-MM-dd HH:mm:ss").ToString() + " " + (((280 - e.Y) / ydif) + ymin).ToString("####0.####").ToString() + String.Format(Environment.NewLine);
                        //textBox1.Select(textBox1.Text.Length, 0);
                        textBox1.SelectionStart = textBox1.Text.Length;
                        textBox1.ScrollToCaret();
                    }
                }
            }
            posicionPrevia = posicionActual;
            if ((e.X >= 0 && e.X < this.canvas.Size.Width) && (e.Y >= 0 && e.Y < this.canvas.Height))
            {
                labelx.Text = e.X.ToString();
                labely.Text = e.Y.ToString();
                var MyFecha_tmp = new DateTime(Convert.ToInt32(tb_FI.Text.Substring(0, 4)), Convert.ToInt32(tb_FI.Text.Substring(5, 2)), Convert.ToInt32(tb_FI.Text.Substring(8, 2)), Convert.ToInt32(tb_FI.Text.Substring(11, 2)), Convert.ToInt32(tb_FI.Text.Substring(14, 2)), 0, DateTimeKind.Utc);
                MyFecha_tmp = MyFecha_tmp.AddMinutes(e.X);
                label1.Text = MyFecha_tmp.ToString("yyyy-MM-dd HH:mm:ss").ToString();
                decimal ymin, ymax, ydif;
                ymin = Convert.ToDecimal(tb_ymin.Text);
                ymax = Convert.ToDecimal(tb_ymax.Text);
                ydif = 280 / (ymax - ymin);
                label2.Text = (((280 - e.Y) / ydif) + ymin).ToString("####0.####").ToString();
            }
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            decimal ymin, ymax, ytmp;
            ymin = 0;
            ymax = 0;
            StreamReader sr = new StreamReader("TestFile.txt");
            String line = sr.ReadLine();
            tb_FI.Text = line.Substring(0,16);
            ymin = Convert.ToDecimal(line.Substring(20,line.Length-20).ToString());
            ymax = ymin;
            while (line != null)
            {
                ytmp = Convert.ToDecimal(line.Substring(20, line.Length - 20).ToString());
                if (ytmp < ymin) ymin = ytmp;
                if (ytmp > ymax) ymax = ytmp;
                tb_FF.Text = line.Substring(0,16);
                line = sr.ReadLine();
            }
            tb_ymin.Text = ymin.ToString();
            tb_ymax.Text = ymax.ToString();
            this.canvas.Enabled = true;
            this.button4.Enabled = true;
            this.button2.Enabled = true;
        }
 
        private void canvas_MouseUp(object sender, MouseEventArgs e)
        {
 
        }
 
        private void canvas_MouseDown(object sender, MouseEventArgs e)
        {
 
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            //
            // Calcular el ancho del objeto picture
            //
            var MyFechaI = new DateTime(Convert.ToInt32(tb_FI.Text.Substring(0, 4)), Convert.ToInt32(tb_FI.Text.Substring(5, 2)), Convert.ToInt32(tb_FI.Text.Substring(8, 2)), Convert.ToInt32(tb_FI.Text.Substring(11, 2)), Convert.ToInt32(tb_FI.Text.Substring(14, 2)), 0, DateTimeKind.Utc);
            var MyFechaF = new DateTime(Convert.ToInt32(tb_FF.Text.Substring(0, 4)), Convert.ToInt32(tb_FF.Text.Substring(5, 2)), Convert.ToInt32(tb_FF.Text.Substring(8, 2)), Convert.ToInt32(tb_FF.Text.Substring(11, 2)), Convert.ToInt32(tb_FF.Text.Substring(14, 2)), 0, DateTimeKind.Utc);
            var MyFecha_tmp = new DateTime(Convert.ToInt32(tb_FF.Text.Substring(0, 4)), Convert.ToInt32(tb_FF.Text.Substring(5, 2)), Convert.ToInt32(tb_FF.Text.Substring(8, 2)), Convert.ToInt32(tb_FF.Text.Substring(11, 2)), Convert.ToInt32(tb_FF.Text.Substring(14, 2)), 0, DateTimeKind.Utc);
            decimal ymin, ymax, ytmp, ydif;
            ymin = Convert.ToDecimal(tb_ymin.Text);
            ymax = Convert.ToDecimal(tb_ymax.Text);
            ydif = 280/(ymax - ymin);
            TimeSpan t = MyFechaF.ToUniversalTime() - MyFechaI.ToUniversalTime();
            //
            // Cambiar tamaño al objeto picture
            //
            this.canvas.Size = new System.Drawing.Size(Convert.ToInt32(t.TotalMinutes + 1), 281);
            //textBox1.Text = "WIDTH: " + (t.TotalMinutes) + " MyFechaF:" + MyFechaF.ToUniversalTime().ToString() + " MyFechaI:" + MyFechaI.ToUniversalTime().ToString() + " size " + this.canvas.Size.Width + " " + this.canvas.Size.Height;
 
            Point posicionPrevia_tmp = new Point(-1, -1);
            StreamReader sr = new StreamReader("TestFile.txt");
            String line = sr.ReadLine();
            while (line != null)
            {
                // Obtener X
                MyFecha_tmp = new DateTime(Convert.ToInt32(line.Substring(0, 4)), Convert.ToInt32(line.Substring(5, 2)), Convert.ToInt32(line.Substring(8, 2)), Convert.ToInt32(line.Substring(11, 2)), Convert.ToInt32(line.Substring(14, 2)), 0, DateTimeKind.Utc);
                t = MyFecha_tmp.ToUniversalTime() - MyFechaI.ToUniversalTime(); //new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
 
                // Obtener Y
                ytmp = Convert.ToDecimal(line.Substring(20, line.Length - 20).ToString());
 
                // Graficar.
                if (posicionPrevia_tmp.X == -1)
                {
                    posicionPrevia_tmp = new Point(Convert.ToInt32(t.TotalMinutes), 281-Convert.ToInt32(((ytmp - ymin) * ydif+1)));   // No se si se deba sumar una unidad +1 (debo de analizar)
                }
                Point posicionActual_tmp = new Point(Convert.ToInt32(t.TotalMinutes), 281-Convert.ToInt32(((ytmp - ymin) * ydif+1)));
                Graphics dibujo = canvas.CreateGraphics();
 
                //Graphics dibujo = Graphics.FromHwnd(this.Handle);
                dibujo.SmoothingMode = SmoothingMode.None;
                dibujo.DrawLine(new Pen(Color.Black), posicionPrevia_tmp, posicionActual_tmp);
                posicionPrevia_tmp = posicionActual_tmp;
                line = sr.ReadLine();
            }
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
 
        private void button4_Click(object sender, EventArgs e)
        {
            //
            // Calcular el ancho del objeto picture
            //
            var MyFechaI = new DateTime(Convert.ToInt32(tb_FI.Text.Substring(0, 4)), Convert.ToInt32(tb_FI.Text.Substring(5, 2)), Convert.ToInt32(tb_FI.Text.Substring(8, 2)), Convert.ToInt32(tb_FI.Text.Substring(11, 2)), Convert.ToInt32(tb_FI.Text.Substring(14, 2)), 0, DateTimeKind.Utc);
            var MyFechaF = new DateTime(Convert.ToInt32(tb_FF.Text.Substring(0, 4)), Convert.ToInt32(tb_FF.Text.Substring(5, 2)), Convert.ToInt32(tb_FF.Text.Substring(8, 2)), Convert.ToInt32(tb_FF.Text.Substring(11, 2)), Convert.ToInt32(tb_FF.Text.Substring(14, 2)), 0, DateTimeKind.Utc);
            var MyFecha_tmp = new DateTime(Convert.ToInt32(tb_FF.Text.Substring(0, 4)), Convert.ToInt32(tb_FF.Text.Substring(5, 2)), Convert.ToInt32(tb_FF.Text.Substring(8, 2)), Convert.ToInt32(tb_FF.Text.Substring(11, 2)), Convert.ToInt32(tb_FF.Text.Substring(14, 2)), 0, DateTimeKind.Utc);
            TimeSpan t = MyFechaF.ToUniversalTime() - MyFechaI.ToUniversalTime();
            //
            // Cambiar tamaño al objeto picture
            //
            this.canvas.Size = new System.Drawing.Size(Convert.ToInt32(t.TotalMinutes + 1), 281);
            this.canvas.Image = null;
            textBox1.Text = "";
        }
    }
}

Espero a alguien le pueda servir.


Saludos
José Luis
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 9
Ha mantenido su posición en Visual CSharp .NET (en relación al último mes)
Gráfica de Visual CSharp .NET

Crear datos en grafica.

Publicado por José Luis (4 intervenciones) el 22/02/2017 17:09:23
diseno

enejecucion

Solo subí la imagen de diseño y la imagen en ejecución.


Saludos
José Luis
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar