Ejemplo n.º 1
0
        private void CreateChartFromRange(object sender, EventArgs e)
        {
            Application.Instance.Invoke(() =>
            {
                DocumentPage tabpage = new DocumentPage();
                var chart            = new Chart();
                object data          = Sheet.CurrentWorksheet.GetRangeData(Sheet.CurrentWorksheet.SelectionRange);
                int firstcol;
                int lastcol;
                int firstrow;
                int lastrow;
                firstcol = Sheet.CurrentWorksheet.SelectionRange.Col;
                lastcol  = Sheet.CurrentWorksheet.SelectionRange.EndCol;
                firstrow = (Sheet.CurrentWorksheet.SelectionRange.Row + 1);
                lastrow  = (Sheet.CurrentWorksheet.SelectionRange.EndRow + 1);
                double d;
                bool hasheaders = !double.TryParse(Sheet.CurrentWorksheet.Cells[(firstrow - 1), firstcol].Data.ToString(), out d);
                object name     = Sheet.CurrentWorksheet.Name;
                string xcol     = Sheet.CurrentWorksheet.SelectionRange.StartPos.ToAddress().Trim(new char[] {
                    '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'
                });
                List <string> ycols = new List <string>();
                for (int i = (firstcol + 1); (i <= lastcol); i++)
                {
                    ycols.Add(Sheet.CurrentWorksheet.Cells[0, i].Address.Trim(new char[] {
                        '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'
                    }));
                }

                if (hasheaders)
                {
                    firstrow++;
                }

                foreach (var item in ycols)
                {
                    chart.SpreadsheetDataSourcesX.Add((name + ("!"
                                                               + (xcol
                                                                  + (firstrow + (":"
                                                                                 + (xcol + lastrow)))))));
                    chart.SpreadsheetDataSourcesY.Add((name + ("!"
                                                               + (item
                                                                  + (firstrow + (":"
                                                                                 + (item + lastrow)))))));
                }

                var chartcontrol = new Charts.ChartControl();

                chartcontrol.Flowsheet   = this.flowsheet;
                chartcontrol.Chart       = chart;
                chartcontrol.Spreadsheet = this.Sheet;

                tabpage.Content = chartcontrol;

                if (hasheaders)
                {
                    chartcontrol.UpdatePlotModelData();
                    var j = 0;
                    for (int i = (firstcol + 1); (i <= lastcol); i++)
                    {
                        ((OxyPlot.PlotModel)chart.PlotModel).Series[j].Title =
                            Sheet.CurrentWorksheet.Cells[firstrow - 2, i].Data.ToString();
                        j += 1;
                    }
                    ((OxyPlot.PlotModel)chart.PlotModel).Axes[0].Title =
                        Sheet.CurrentWorksheet.Cells[firstrow - 2, firstcol].Data.ToString();
                    ((OxyPlot.PlotModel)chart.PlotModel).Axes[1].Title = "";
                    if (((OxyPlot.PlotModel)chart.PlotModel).Series.Count == 1)
                    {
                        ((OxyPlot.PlotModel)chart.PlotModel).Axes[1].Title =
                            Sheet.CurrentWorksheet.Cells[firstrow - 2, firstcol + 1].Data.ToString();
                    }
                }

                tabpage.Shown += (s1, e1) =>
                {
                    chartcontrol.UpdatePlotModelData();
                    chartcontrol.UpdatePropertiesLayout();
                };

                tabpage.Text = chart.DisplayName;
                flowsheet.Charts.Add(chart.ID, chart);
                flowsheet.AddChart.Invoke(tabpage);
            });
        }
Ejemplo n.º 2
0
        public void Init()
        {
            TabControl = new DocumentControl();

            this.Shown += (sender, e) =>
            {
                var selectedtab = TabControl.SelectedPage;
                if (selectedtab != null)
                {
                    var chart = (ChartControl)selectedtab.Content;
                    Application.Instance.Invoke(() =>
                    {
                        chart.Splitter.Position = chart.Splitter.Width - 350;
                        chart.UpdatePlotModelData();
                        chart.UpdatePropertiesLayout();
                    });
                }
            };

            this.Load += (sender, e) =>
            {
                Application.Instance.Invoke(() =>
                {
                    if ((Flowsheet.Charts.Count > 0) && !IsLoaded)
                    {
                        foreach (var item in Flowsheet.Charts)
                        {
                            DocumentPage tabpage = new DocumentPage();
                            var ccontrol         = new ChartControl {
                                Chart = (Chart)item.Value, Flowsheet = Flowsheet, Spreadsheet = (ReoGridControl)Flowsheet.GetSpreadsheetObjectFunc?.Invoke()
                            };
                            tabpage.Content = ccontrol;
                            TabControl.Pages.Add(tabpage);
                            tabpage.Text    = item.Value.DisplayName;
                            tabpage.Closed += Tabpage_Closed;
                            tabpage.Shown  += (s1, e1) => {
                                ccontrol.UpdatePlotModelData();
                                ccontrol.UpdatePropertiesLayout();
                            };
                        }
                    }
                    IsLoaded = true;
                });
            };

            var l1 = new Label {
                Text = "Create and view Charts using data from Flowsheet Objects or Spreadsheet Cell Ranges."
            };

            var b1 = new Button {
                Text = "Add New 2D XY Chart"
            };

            b1.Click += (s, e) =>
            {
                Application.Instance.Invoke((Action)(() =>
                {
                    DocumentPage tabpage = new DocumentPage();
                    var chart = new Chart();
                    tabpage.Text = chart.DisplayName;
                    var ccontrol = new ChartControl {
                        Chart = chart, Flowsheet = Flowsheet, Spreadsheet = (ReoGridControl)Flowsheet.GetSpreadsheetObjectFunc?.Invoke()
                    };
                    tabpage.Content = ccontrol;
                    ccontrol.UpdatePlotModelData();
                    ccontrol.UpdatePropertiesLayout();
                    TabControl.Pages.Add(tabpage);
                    tabpage.Closed += Tabpage_Closed;
                    tabpage.Shown += (s1, e1) => {
                        ccontrol.UpdatePlotModelData();
                        ccontrol.UpdatePropertiesLayout();
                    };
                }));
            };

            var tl = new TableLayout {
                Spacing = new Eto.Drawing.Size(5, 5), Padding = new Eto.Drawing.Padding(5)
            };

            var tr = new TableRow {
                Cells = { l1, b1 }
            };

            tr.Cells[0].ScaleWidth = true;

            tl.Rows.Add(tr);

            this.BeginVertical();
            this.Add(tl, true);
            this.Add(TabControl, true, true);
            this.BeginVertical();
        }