Exemplo n.º 1
0
        public ChartUI()
        {
            InitializeComponent();
            m_chart.Options.Orthographic          = true;
            m_chart.Options.SceneBorderThickness  = 1;
            m_chart.Options.SceneBorderColour     = Colour32.Black;
            m_chart.Scene.ContextMenu.DataContext = this;

            m_obj0 = new View3d.Object(
                "test_object", 0xFFFFFFFF, 5, 18, 1,
                new View3d.Vertex[]
            {
                new View3d.Vertex(new v4(+0, +1, +0, 1), new v4(+0.00f, +1.00f, +0.00f, 0), 0xffff0000, new v2(0.50f, 1)),
                new View3d.Vertex(new v4(-1, -1, -1, 1), new v4(-0.57f, -0.57f, -0.57f, 0), 0xff00ff00, new v2(0.00f, 0)),
                new View3d.Vertex(new v4(-1, -1, +1, 1), new v4(-0.57f, -0.57f, +0.57f, 0), 0xff0000ff, new v2(0.25f, 0)),
                new View3d.Vertex(new v4(+1, -1, +1, 1), new v4(+0.57f, -0.57f, +0.57f, 0), 0xffff00ff, new v2(0.50f, 0)),
                new View3d.Vertex(new v4(+1, -1, -1, 1), new v4(+0.57f, -0.57f, -0.57f, 0), 0xff00ffff, new v2(0.75f, 0)),
            },
                new ushort[]
            {
                0, 1, 2,
                0, 2, 3,
                0, 3, 4,
                0, 4, 1,
                4, 3, 2,
                2, 1, 4,
            },
                new View3d.Nugget[]
            {
                new View3d.Nugget(View3d.ETopo.TriList, View3d.EGeom.Vert | View3d.EGeom.Norm | View3d.EGeom.Colr),
            },
                null);
            m_chart.BuildScene += (s, a) =>
            {
                m_chart.Scene.Window.AddObject(m_obj0);
            };

            m_series = new ChartDataSeries("waves", ChartDataSeries.EFormat.XRealYReal);
            m_series.Options.Colour     = Colour32.Blue;
            m_series.Options.PlotType   = ChartDataSeries.EPlotType.Bar;
            m_series.Options.PointStyle = EPointStyle.Triangle;
            m_series.Options.PointSize  = 50f;
            m_series.Options.LineWidth  = 3f;
            m_series.Chart = m_chart;
            {
                using var lk = m_series.Lock();
                for (int i = 0; i != 100000; ++i)
                {
                    lk.Add(new ChartDataSeries.Pt(0.01 * i, Math.Sin(0.01 * i * Math_.Tau)));
                }
            }

            m_legend = new ChartDataLegend();
            m_chart.Elements.Add(m_legend);

            MyLegendItems = new ListCollectionView(new[] { m_series });

            ShowBoobs   = Command.Create(this, ShowBoobsInternal);
            DataContext = this;
        }
Exemplo n.º 2
0
        public ChartUI()
        {
            InitializeComponent();
            m_chart = Controls.Add2(new ChartControl {
                Dock = DockStyle.Fill, Title = "My Chart"
            });
            m_chart.Options.Orthographic = true;
            m_chart.XAxis.Label          = "X Axis";
            m_chart.YAxis.Label          = "Y Axis";

            m_obj0 = new View3d.Object(
                "test_object", 0xFFFFFFFF, 5, 18, 1,
                new View3d.Vertex[]
            {
                new View3d.Vertex(new v4(+0, +1, +0, 1), new v4(+0.00f, +1.00f, +0.00f, 0), 0xffff0000, new v2(0.50f, 1)),
                new View3d.Vertex(new v4(-1, -1, -1, 1), new v4(-0.57f, -0.57f, -0.57f, 0), 0xff00ff00, new v2(0.00f, 0)),
                new View3d.Vertex(new v4(+1, -1, -1, 1), new v4(+0.57f, -0.57f, -0.57f, 0), 0xff0000ff, new v2(0.25f, 0)),
                new View3d.Vertex(new v4(+1, -1, +1, 1), new v4(+0.57f, -0.57f, +0.57f, 0), 0xffff00ff, new v2(0.50f, 0)),
                new View3d.Vertex(new v4(-1, -1, +1, 1), new v4(-0.57f, -0.57f, +0.57f, 0), 0xff00ffff, new v2(0.75f, 0)),
            },
                new ushort[]
            {
                0, 1, 2,
                0, 2, 3,
                0, 3, 4,
                0, 4, 1,
                4, 3, 2,
                2, 1, 4,
            },
                new View3d.Nugget[]
            {
                new View3d.Nugget(View3d.ETopo.TriList, View3d.EGeom.Vert | View3d.EGeom.Norm | View3d.EGeom.Colr),
            }, null);
            m_chart.ChartRendering += (s, a) =>
            {
                a.AddToScene(m_obj0);
            };

            m_series = new ChartDataSeries("waves", ChartDataSeries.EFormat.XRealYReal);
            using (var lk = m_series.Lock())
            {
                for (int i = 0; i != 100000; ++i)
                {
                    lk.Add(new ChartDataSeries.Pt(0.01 * i, Math.Sin(0.01 * i * Math_.Tau)));
                }
            }
            m_series.Options.Colour     = Colour32.Blue;
            m_series.Options.PlotType   = ChartDataSeries.EPlotType.Bar;
            m_series.Options.PointStyle = ChartDataSeries.EPointStyle.Triangle;
            m_series.Options.PointSize  = 50f;
            m_series.Options.LineWidth  = 3f;
            m_series.Chart = m_chart;

            m_legend = new ChartDataLegend();
            m_chart.Elements.Add(m_legend);
        }
Exemplo n.º 3
0
        private void  // ERROR: Handles clauses are not supported in C#
        moBarData_DataLoadComplete(object sender, T4.API.ChartData.DataLoadCompleteEventArgs e)
        {
            // NOTE: This event is raised on it's own thread. If you are updating a GUI application with the chart data (like this example), don't forget that you
            //       MUST marshall this update onto the GUI thread before you modify any GUI components.
            // (This is the same for all T4 API events.)

            if (this.InvokeRequired)
            {
                // An invoke is required to update the GUI, simply invoke back to this same mthod.
                this.BeginInvoke(new T4.API.ChartData.DataLoadCompleteEventHandler(moBarData_DataLoadComplete), new object[] {
                    sender,
                    e
                });

                // Don't forget to exit now!
                return;
            }

            // On the GUI thread now, update the chart.

            if (e.Status == DataLoadStatus.Failed)
            {
                Trace.WriteLine("IChartDataRequest_ChartDataComplete: Chart data request failed.");
                return;
            }
            else
            {
                // Sometimes, you won't get all the historical data you requested. This could happen if there isn't chart data available all the back to the start date you requested.
                Trace.WriteLine(string.Format("IChartDataRequest_ChartDataComplete: Status: {0}, Dates Requested: {1}, Dates Received: {2}", e.Status, e.DateRangeRequested, e.DateRangeProcessed));
            }

            chart1.Series["candlestickSeries"].Points.Clear();
            chart1.Series["candlestickVolumeSeries"].Points.Clear();
            chart1.Series["movingAverageSeries"].Points.Clear();
            int dataPointHigh = int.MinValue;
            int dataPointLow  = int.MaxValue;

            // Before iterating the data collection, you MUST lock it. This will prevent live trade updates from modifying the collection as you read it.
            moBarData.Lock();


            try {
                for (int i = 0; i <= moBarData.TradeBars.Count - 1; i++)
                {
                    T4.API.ChartData.BarDataPoint oBar = (T4.API.ChartData.BarDataPoint)moBarData.TradeBars[i];

                    Trace.WriteLine(string.Format("TradeDate: {6}, Time: {5}, Open: {0}, High: {1}, Low: {2}, Close: {3}, Volume: {4}", oBar.OpenTicks, oBar.HighTicks, oBar.LowTicks, oBar.CloseTicks, oBar.Volume, oBar.Time, oBar.TradeDate));

                    moTable.Rows.Add(i, oBar.TradeDate, oBar.Time, oBar.OpenTicks, oBar.HighTicks, oBar.LowTicks, oBar.CloseTicks, oBar.Volume);

                    // Add candlestick to chart (high, low, open, close).
                    object[] multipleValues = new object[] { oBar.HighTicks, oBar.LowTicks, oBar.OpenTicks, oBar.CloseTicks };
                    chart1.Series[0].Points.AddXY(oBar.Time, multipleValues);
                    chart1.Series[1].Points.AddXY(oBar.Time, oBar.Volume);

                    // See if our maximum and minimum values on the chart have changed (we will use this for axis scaling).
                    dataPointHigh = Math.Max(dataPointHigh, oBar.HighTicks);
                    dataPointLow  = Math.Min(dataPointLow, oBar.LowTicks);
                }

                DataGridView1.AutoResizeColumns();
                chart1.ChartAreas[0].AxisY.Minimum = dataPointLow;
                chart1.ChartAreas[0].AxisY.Maximum = dataPointHigh;

                /*
                 * IList<DateTime> listx = new List<DateTime>();
                 * IList<double> listy = new List<double>();
                 *
                 * //iterate and add your values to the two lists: listx and listy
                 *
                 * //when you're done, bind the lists to the points collection
                 * yourSeries.Points.DataBindXY(listx, listy);
                 */
            } catch (Exception ex) {
                Trace.WriteLine("Error loading chart data: " + ex.ToString());
            } finally {
                // If you don't be sure to unlock the data collection, you probably won't get any live trade updates.
                moBarData.Unlock();
            }
        }