Example #1
0
        private void textBox_Bandwidth_TextChanged(object sender, EventArgs e)
        {
            if (textBox_Bandwidth.Text == "")
            {
                return;
            }
            Span = long.Parse(textBox_Bandwidth.Text);
            if (Span == 0)
            {
                return;
            }

            double[] yLoess = new double[rows - 1];
            QLOESS(ref Y, ref X, ref yLoess, Span);

            double[,] data = new double[rows - 1, 1];
            int j;

            for (j = 1; j < rows; j++)
            {
                data[j - 1, 0] = yLoess[j - 1];
            }

            ((Excel.Range)worksheet.Cells[start_row, start_col + cols]).Value2 = "Smooth Y";
            Excel.Range c1    = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols];
            Excel.Range c2    = (Excel.Range)worksheet.Cells[start_row + 1 + rows - 2, start_col + cols];
            Excel.Range range = worksheet.get_Range(c1, c2);
            range.Value = data;

            chart.Refresh();
        }
Example #2
0
        private void textBox_Bandwidth_TextChanged(object sender, EventArgs e)
        {
            // textBox_Bandwidth.Text = Convert.ToString(hScrollBar_Parameter1.Value);
            if (textBox_Bandwidth.Text == "")
            {
                return;
            }
            Bandwidth = double.Parse(textBox_Bandwidth.Text);;
            if (Bandwidth == 0)
            {
                return;
            }

            double Pdensity = Bandwidth * 100;
            double Maxtemp  = 1000;
            int    i;

            double[,] data = new double[rows, 2];
            for (i = 1; i < rows; i++)
            {
                data[i - 1, 0] = Math.Floor(double.Parse(str[i, 0]) * Maxtemp / Pdensity) * Pdensity / Maxtemp;
                data[i - 1, 1] = Math.Floor(double.Parse(str[i, 1]) * Maxtemp / Pdensity) * Pdensity / Maxtemp;
            }

            //worksheet worksheet = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);

            Excel.Range c1    = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols];
            Excel.Range c2    = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols + cols - 1];
            Excel.Range range = worksheet.get_Range(c1, c2);
            range.Value = data;

            //Microsoft.Office.Interop.Excel.Chart chart = Globals.ThisAddIn.Application.ActiveChart;
            c1 = (Excel.Range)worksheet.Cells[start_row, start_col + cols];
            c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols + cols - 1];
            chart.SetSourceData(worksheet.get_Range(c1, c2), Excel.XlRowCol.xlColumns);
            chart.Refresh();
            worksheet.Activate();
        }
Example #3
0
        private void textBox_Bandwidth_TextChanged(object sender, EventArgs e)
        {
            if (textBox_Bandwidth.Text == "" | flag == 0)
            {
                return;
            }
            ThreholdArea = double.Parse(textBox_Bandwidth.Text);;
            if (ThreholdArea == 0)
            {
                return;
            }

            ((Excel.Range)worksheet.Cells[start_row + 1, start_col + cols]).Value2 = ThreholdArea;

            double[,] data = new double[rows - 1, 3];
            for (int i = 1; i < rows; i++)
            {
                if (double.Parse(str[i, 1]) > ThreholdArea)
                {
                    data[i - 1, 2] = double.Parse(str[i, 1]) - ThreholdArea;
                    data[i - 1, 1] = 0;
                    data[i - 1, 0] = ThreholdArea - data[i - 1, 1];
                }
                else
                {
                    data[i - 1, 2] = 0;
                    data[i - 1, 1] = ThreholdArea - double.Parse(str[i, 1]);
                    data[i - 1, 0] = ThreholdArea - data[i - 1, 1];
                }
            }

            //double Max_data = Double.MinValue;
            //double Min_data = Double.MaxValue;
            //for (int i = 1; i < rows; i++)
            //{
            //    if (data[i - 1, 0] > Max_data) Max_data = data[i - 1, 0];
            //    if (data[i - 1, 1] < Min_data) Min_data = data[i - 1, 1];
            //}

            Excel.Range c1    = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 1];
            Excel.Range c2    = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols + 3];
            Excel.Range range = worksheet.get_Range(c1, c2);
            range.Value = data;

            chart.Refresh();
            //worksheet.Activate();
        }
Example #4
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            //Instantiate the Application object.
            Excel.Application ExcelApp = Application;
            //Add a Workbook.
            Excel.Workbook objBook = ExcelApp.Workbooks.Add(System.Reflection.Missing.Value);

            // Access a Vsto Worksheet
            Microsoft.Office.Interop.Excel.Worksheet nativeWorksheet = Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet;
            Microsoft.Office.Tools.Excel.Worksheet   sheet           = Globals.Factory.GetVstoObject(nativeWorksheet);

            //Add sample data for pie chart
            //Add headings in A1 and B1
            sheet.Cells[1, 1] = "Products";
            sheet.Cells[1, 2] = "Users";

            //Add data from A2 till B4
            sheet.Cells[2, 1] = "Aspose.Cells";
            sheet.Cells[2, 2] = 10000;
            sheet.Cells[3, 1] = "Aspose.Slides";
            sheet.Cells[3, 2] = 8000;
            sheet.Cells[4, 1] = "Aspose.Words";
            sheet.Cells[4, 2] = 12000;

            //Chart reference
            Microsoft.Office.Tools.Excel.Chart productsChart;

            //Add a Pie Chart
            productsChart           = sheet.Controls.AddChart(0, 105, 330, 200, "ProductUsers");
            productsChart.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlPie;

            //Set chart title
            productsChart.HasTitle        = true;
            productsChart.ChartTitle.Text = "Users";

            //Gets the cells that define the data to be charted.
            Microsoft.Office.Interop.Excel.Range chartRange = sheet.get_Range("A2", "B4");
            productsChart.SetSourceData(chartRange, missing);

            //Access the Active workbook from Vsto sheet
            Microsoft.Office.Interop.Excel.Workbook workbook = sheet.Application.ActiveWorkbook;

            //Save the copy of workbook as OutputVsto.xlsx
            workbook.SaveCopyAs("OutputVsto.xlsx");
        }
Example #5
0
        public ColumnFrequency()
        {
            InitializeComponent();
            //hScrollBar_Parameter1.Value = 2;
            //Graphics Graphic = new Graphics();
            Bandwidth = double.Parse(textBox_Bandwidth.Text);
            //if (Form_Parater.flag == 0) return;
            //int rows = 1;
            //int cols = 1;
            //string[,] str = new string[1, 1];
            Graphic.RangeData(ref str, ref rows, ref cols);

            worksheet = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);

            Excel.Range activecells = Globals.ThisAddIn.Application.ActiveCell;
            start_col = activecells.Column;
            start_row = activecells.Row;

            Max_Value = Double.MinValue;
            Min_Value = Double.MaxValue;
            for (int i = 1; i < rows; i++)
            {
                if (double.Parse(str[i, 0]) > Max_Value)
                {
                    Max_Value = double.Parse(str[i, 0]);
                }
                if (double.Parse(str[i, 0]) < Min_Value)
                {
                    Min_Value = double.Parse(str[i, 0]);
                }
            }

            int Nrows = Convert.ToInt32((Max_Value - Min_Value) / Bandwidth + 2);

            double[,] data = new double[Nrows, 1];
            int idx = 0;

            for (int i = 1; i < rows; i++)
            {
                idx          = Convert.ToInt32((double.Parse(str[i, 0]) - Min_Value) / Bandwidth);
                data[idx, 0] = data[idx, 0] + 1;
            }
            data[Nrows - 2, 0] = data[Nrows - 2, 0] + data[Nrows - 1, 0];


            double[,] x     = new double[Nrows - 1, 1];
            string[,] label = new string[Nrows - 1, 1];
            for (int i = 0; i < Nrows - 1; i++)
            {
                label[i, 0] = "[" + Convert.ToString(Math.Floor((i * Bandwidth + Min_Value) * 100) / 100) + ","
                              + Convert.ToString(Math.Floor(((i + 1) * Bandwidth + Min_Value) * 100) / 100) + ")";
                //((Excel.Range)worksheet.Cells[start_row + 1 + i, start_col + cols + 1]).Value2 = label[i];
                //((Excel.Range)worksheet.Cells[start_row + 1 + i, start_col + cols + 3]).Value2 = data[i];
                x[i, 0] = i * Bandwidth + Min_Value;
            }

            ((Excel.Range)worksheet.Cells[start_row, start_col + cols + 1]).Value2 = "X bandwidth";
            ((Excel.Range)worksheet.Cells[start_row, start_col + cols + 2]).Value2 = "X axis";
            ((Excel.Range)worksheet.Cells[start_row, start_col + cols + 3]).Value2 = "Y axis";

            Excel.Range c1    = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 1];
            Excel.Range c2    = (Excel.Range)worksheet.Cells[start_row + Nrows - 1, start_col + cols + 1];
            Excel.Range range = worksheet.get_Range(c1, c2);
            range.Value = label;

            c1          = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 2];
            c2          = (Excel.Range)worksheet.Cells[start_row + Nrows - 1, start_col + cols + 2];
            range       = worksheet.get_Range(c1, c2);
            range.Value = x;

            c1          = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 3];
            c2          = (Excel.Range)worksheet.Cells[start_row + Nrows, start_col + cols + 3];
            range       = worksheet.get_Range(c1, c2);
            range.Value = data;
            ((Excel.Range)worksheet.Cells[start_row + Nrows, start_col + cols + 3]).Value2 = "";;

            string ChartOrder = "FrequencyColumn" + Convert.ToString(Nchart);

            chart  = worksheet.Controls.AddChart(300, 50, 450, 400, ChartOrder);
            Nchart = Nchart + 1;

            c1 = (Excel.Range)worksheet.Cells[start_row, start_col + cols + 2];
            c2 = (Excel.Range)worksheet.Cells[start_row + Nrows - 1, start_col + cols + 3];
            chart.SetSourceData(worksheet.get_Range(c1, c2), Excel.XlRowCol.xlColumns);
            chart.ChartType = Excel.XlChartType.xlColumnClustered;

            Excel.SeriesCollection series = (Excel.SeriesCollection)chart.SeriesCollection();

            if (series.Count == 2)
            {
                Excel.Series Sseries2 = series.Item(2);
                Sseries2.Delete();
            }

            Excel.Series Sseries = series.Item(1);
            c1 = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 2];
            c2 = (Excel.Range)worksheet.Cells[start_row + Nrows - 1, start_col + cols + 2];
            Sseries.XValues = worksheet.get_Range(c1, c2);

            c1             = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 3];
            c2             = (Excel.Range)worksheet.Cells[start_row + Nrows - 1, start_col + cols + 3];
            Sseries.Values = worksheet.get_Range(c1, c2);


            Sseries.Format.Fill.Visible       = Office.MsoTriState.msoTrue;
            Sseries.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 88, 180, 13).ToArgb();
            Sseries.Format.Line.Visible       = Office.MsoTriState.msoTrue;
            Sseries.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 0, 0, 0).ToArgb();

            Excel.ChartGroup group = (Excel.ChartGroup)chart.ChartGroups(1);
            group.GapWidth = 0;


            chart.HasLegend = false;
            chart.HasTitle  = false;
            worksheet.Activate();
        }
Example #6
0
        private void textBox_Bandwidth_TextChanged(object sender, EventArgs e)
        {
            if (textBox_Bandwidth.Text == "")
            {
                return;
            }
            Bandwidth = double.Parse(textBox_Bandwidth.Text);;
            if (Bandwidth == 0)
            {
                return;
            }

            int Nrows = Convert.ToInt32((Max_Value - Min_Value) / Bandwidth + 2);

            double[,] data = new double[Nrows, 1];
            int idx = 0;

            for (int i = 1; i < rows; i++)
            {
                idx          = Convert.ToInt32((double.Parse(str[i, 0]) - Min_Value) / Bandwidth);
                data[idx, 0] = data[idx, 0] + 1;
            }
            data[Nrows - 2, 0] = data[Nrows - 2, 0] + data[Nrows - 1, 0];


            double[,] x     = new double[Nrows - 1, 1];
            string[,] label = new string[Nrows - 1, 1];
            for (int i = 0; i < Nrows - 1; i++)
            {
                label[i, 0] = "[" + Convert.ToString(Math.Floor((i * Bandwidth + Min_Value) * 100) / 100) + ","
                              + Convert.ToString(Math.Floor(((i + 1) * Bandwidth + Min_Value) * 100) / 100) + ")";
                //((Excel.Range)worksheet.Cells[start_row + 1 + i, start_col + cols + 1]).Value2 = label[i];
                //((Excel.Range)worksheet.Cells[start_row + 1 + i, start_col + cols + 3]).Value2 = data[i];
                x[i, 0] = i * Bandwidth + Min_Value;
            }

            ((Excel.Range)worksheet.Cells[start_row, start_col + cols + 1]).Value2 = "X bandwidth";
            ((Excel.Range)worksheet.Cells[start_row, start_col + cols + 2]).Value2 = "X axis";
            ((Excel.Range)worksheet.Cells[start_row, start_col + cols + 3]).Value2 = "Y axis";

            Excel.Range c1    = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 1];
            Excel.Range c2    = (Excel.Range)worksheet.Cells[start_row + Nrows - 1, start_col + cols + 1];
            Excel.Range range = worksheet.get_Range(c1, c2);
            range.Value = label;

            c1          = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 2];
            c2          = (Excel.Range)worksheet.Cells[start_row + Nrows - 1, start_col + cols + 2];
            range       = worksheet.get_Range(c1, c2);
            range.Value = x;

            c1          = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 3];
            c2          = (Excel.Range)worksheet.Cells[start_row + Nrows, start_col + cols + 3];
            range       = worksheet.get_Range(c1, c2);
            range.Value = data;
            ((Excel.Range)worksheet.Cells[start_row + Nrows, start_col + cols + 3]).Delete();;

            c1 = (Excel.Range)worksheet.Cells[start_row, start_col + cols + 2];
            c2 = (Excel.Range)worksheet.Cells[start_row + Nrows - 1, start_col + cols + 3];
            chart.SetSourceData(worksheet.get_Range(c1, c2), Excel.XlRowCol.xlColumns);

            Excel.SeriesCollection series = (Excel.SeriesCollection)chart.SeriesCollection();

            Excel.Series Sseries2 = series.Item(2);
            Sseries2.Delete();

            Excel.Series Sseries = series.Item(1);
            c1 = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 2];
            c2 = (Excel.Range)worksheet.Cells[start_row + Nrows - 1, start_col + cols + 2];
            Sseries.XValues = worksheet.get_Range(c1, c2);

            c1             = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 3];
            c2             = (Excel.Range)worksheet.Cells[start_row + Nrows - 1, start_col + cols + 3];
            Sseries.Values = worksheet.get_Range(c1, c2);

            chart.Refresh();
            worksheet.Activate();
        }
Example #7
0
        public CurveLOESS()
        {
            InitializeComponent();

            //int rows = 1;
            //int cols = 1;
            //string[,] str = new string[1, 1];
            Graphic.RangeData(ref str, ref rows, ref cols);

            worksheet = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);
            Excel.Range activecells = Globals.ThisAddIn.Application.ActiveCell;
            start_col = activecells.Column;
            start_row = activecells.Row;

            Y = new double[rows - 1];
            X = new double[rows - 1];
            int j;

            for (j = 1; j < rows; j++)
            {
                X[j - 1] = double.Parse(str[j, 0]);
                Y[j - 1] = double.Parse(str[j, 1]);
            }

            Span = long.Parse(textBox_Bandwidth.Text);
            double[] yLoess = new double[rows - 1];
            QLOESS(ref Y, ref X, ref yLoess, Span);

            double[,] data = new double[rows - 1, 1];
            for (j = 1; j < rows; j++)
            {
                data[j - 1, 0] = yLoess[j - 1];
            }

            ((Excel.Range)worksheet.Cells[start_row, start_col + cols]).Value2 = "Smooth Y";
            Excel.Range c1    = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols];
            Excel.Range c2    = (Excel.Range)worksheet.Cells[start_row + 1 + rows - 2, start_col + cols];
            Excel.Range range = worksheet.get_Range(c1, c2);
            range.Value = data;

            c1 = (Excel.Range)worksheet.Cells[start_row, start_col];
            c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols];

            string ChartOrder = "CurveLOESS" + Convert.ToString(Nchart);

            chart  = worksheet.Controls.AddChart(250, 50, 450, 400, ChartOrder);
            Nchart = Nchart + 1;

            chart.SetSourceData(worksheet.get_Range(c1, c2), Excel.XlRowCol.xlColumns);
            chart.ChartType = Excel.XlChartType.xlXYScatter;

            Excel.SeriesCollection series = (Excel.SeriesCollection)chart.SeriesCollection();

            Excel.Series Sseries2 = series.Item(2);
            Sseries2.Format.Line.Visible = Office.MsoTriState.msoFalse;
            Sseries2.Format.Fill.Solid();
            Sseries2.Format.Fill.Visible = Office.MsoTriState.msoCTrue;
            //Sseries2.Format.Fill.BackColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb();
            //Sseries2.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255,229, 184,0).ToArgb();
            //Sseries2.Format.Fill.Transparency = 0.6F;

            Sseries2.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleCircle;
            Sseries2.MarkerSize  = 6;

            Excel.Series Sseries3 = series.Item(3);
            Sseries3.Format.Fill.Visible = Office.MsoTriState.msoFalse;
            Sseries3.Format.Line.Visible = Office.MsoTriState.msoTrue;
            Sseries3.MarkerStyle         = Excel.XlMarkerStyle.xlMarkerStyleNone;
            //Sseries3.Format.Line.ForeColor.RGB= System.Drawing.Color.FromArgb(255, 248, 118, 109).ToArgb();
            Sseries3.Format.Line.Weight = 1.25F;

            Excel.Series Sseries1 = series.Item(1);
            Sseries1.Delete();
        }
Example #8
0
        public ColumnColor()
        {
            InitializeComponent();

            Graphic.RangeData(ref str, ref rows, ref cols);

            worksheet = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);
            Excel.Range activecells = Globals.ThisAddIn.Application.ActiveCell;
            start_col = activecells.Column;
            start_row = activecells.Row;

            Excel.Range c1 = (Excel.Range)worksheet.Cells[start_row, start_col];
            Excel.Range c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols - 2];

            string ChartOrder = "ColorColumn" + Convert.ToString(Nchart);

            chart  = worksheet.Controls.AddChart(250, 50, 450, 400, ChartOrder);
            Nchart = Nchart + 1;

            chart.SetSourceData(worksheet.get_Range(c1, c2), Excel.XlRowCol.xlColumns);
            chart.ChartType = Excel.XlChartType.xlColumnClustered;

            Excel.SeriesCollection series = (Excel.SeriesCollection)chart.SeriesCollection();

            if (series.Count == 2)
            {
                Excel.Series Sseries2 = series.Item(2);
                Sseries2.Delete();
            }

            Excel.Series Sseries = series.Item(1);
            c1 = (Excel.Range)worksheet.Cells[start_row + 1, start_col];
            c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col];
            Sseries.XValues = worksheet.get_Range(c1, c2);

            c1             = (Excel.Range)worksheet.Cells[start_row + 1, start_col + 1];
            c2             = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + 1];
            Sseries.Values = worksheet.get_Range(c1, c2);

            Excel.Point point;
            int[]       HSV0 = new int[3];

            RGB0 = System.Drawing.Color.FromArgb(255, 96, 157, 202);
            System.Drawing.Color RGB1 = System.Drawing.Color.FromArgb(255, 96, 157, 202);

            Graphic.RGB2HSV(RGB0, ref HSV0);

            Max_Value = Double.MinValue;
            Min_Value = Double.MaxValue;
            for (int i = 1; i < rows; i++)
            {
                if (double.Parse(str[i, 2]) > Max_Value)
                {
                    Max_Value = double.Parse(str[i, 1]);
                }
                if (double.Parse(str[i, 2]) < Min_Value)
                {
                    Min_Value = double.Parse(str[i, 1]);
                }
            }

            int[] HSV = new int[3];
            HSV0.CopyTo(HSV, 0);
            double ratio;

            Hrange = double.Parse(textBox_Bandwidth.Text);
            for (int i = 1; i < rows; i++)
            {
                point = (Excel.Point)Sseries.Points(i);
                point.Format.Fill.Solid();
                point.Format.Fill.Visible       = Office.MsoTriState.msoCTrue;
                point.Format.Fill.BackColor.RGB = System.Drawing.Color.FromArgb(255, 229, 229, 229).ToArgb();

                ratio  = (double.Parse(str[i, 2]) - Min_Value) / (Max_Value - Min_Value);
                HSV[2] = HSV0[2] + Convert.ToInt32(Hrange * (ratio - 0.5));
                Graphic.HSV2RGB(ref RGB1, HSV);
                point.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, RGB1.B, RGB1.G, RGB1.R).ToArgb();
                point.Format.Fill.Transparency  = 0.0F;
            }
            //Sseries.MarkerBackgroundColor = System.Drawing.Color.FromArgb(255, 77, 175, 74).ToArgb();
            //Sseries.MarkerForegroundColor = System.Drawing.Color.FromArgb(255, 77, 175, 74).ToArgb();
            Sseries.Format.Line.Visible       = Office.MsoTriState.msoCTrue;
            Sseries.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
            Sseries.Format.Line.Weight        = 0.75F;

            Excel.ChartGroup group = (Excel.ChartGroup)chart.ChartGroups(1);
            group.GapWidth = 0;

            chart.HasLegend = false;
            chart.HasTitle  = false;
            //chart.ChartTitle.Delete();
            worksheet.Activate();
        }
Example #9
0
        public BubbleRelationShip()
        {
            InitializeComponent();

            ratio = double.Parse(textBox_Bandwidth.Text);;

            Graphic.RangeData(ref str, ref rows, ref cols);

            worksheet = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);

            Excel.Range activecells = Globals.ThisAddIn.Application.ActiveCell;
            start_col = activecells.Column;
            start_row = activecells.Row;

            int i, j;

            for (j = 1; j < cols; j++)
            {
                ((Excel.Range)worksheet.Cells[start_row + rows + 1, start_col + j]).Value2 = str[0, j];
            }

            for (j = 1; j < rows; j++)
            {
                ((Excel.Range)worksheet.Cells[start_row + rows + 1 + j, start_col]).Value2 = str[j, 0];
            }


            for (i = 1; i < rows; i++)
            {
                for (j = 1; j < cols; j++)
                {
                    ((Excel.Range)worksheet.Cells[start_row + rows + 1 + i, start_col + j]).Value2 = i;// str[i, 0];
                }
            }

            ((Excel.Range)worksheet.Cells[start_row + rows + 1 + rows, start_col]).Value2 = "Assistant1";
            for (j = 1; j < rows; j++)
            {
                ((Excel.Range)worksheet.Cells[start_row + rows + 1 + rows, start_col + j]).Value2 = 0;
            }

            ((Excel.Range)worksheet.Cells[start_row + rows + 1 + rows + 1, start_col]).Value2 = "Assistant2";
            for (j = 1; j < rows; j++)
            {
                ((Excel.Range)worksheet.Cells[start_row + rows + 1 + rows + 1, start_col + j]).Value2 = j;
            }


            Excel.Range c1 = (Excel.Range)worksheet.Cells[start_row + rows + 1, start_col];
            Excel.Range c2 = (Excel.Range)worksheet.Cells[start_row + rows + 1 + rows + 1, start_col + rows - 1];

            string ChartOrder = "BubbleRelationShip" + Convert.ToString(Nchart);

            chart  = worksheet.Controls.AddChart(250, 50, 450, 400, ChartOrder);
            Nchart = Nchart + 1;

            chart.SetSourceData(worksheet.get_Range(c1, c2), Excel.XlRowCol.xlRows);
            chart.ChartType = Excel.XlChartType.xlXYScatter;

            //double ratio = 21;
            //double Max_size = 0;
            Max_size = Double.MinValue;
            Min_size = Double.MaxValue;
            for (i = 1; i < rows; i++)
            {
                for (j = 1; j < cols; j++)
                {
                    if (double.Parse(str[i, j]) > Max_size)
                    {
                        Max_size = double.Parse(str[i, j]);
                    }
                    if (double.Parse(str[i, j]) < Min_size)
                    {
                        Min_size = double.Parse(str[i, j]);
                    }
                }
            }

            Max_size = Math.Sqrt(Max_size);
            Min_size = Math.Sqrt(Min_size);

            Excel.SeriesCollection series = (Excel.SeriesCollection)chart.SeriesCollection();

            Excel.Point  point;
            Excel.Series Sseries;
            int          SquareSize;

            RGB0 = System.Drawing.Color.FromArgb(255, 248, 118, 109);
            for (i = 1; i < rows; i++)
            {
                Sseries = series.Item(i);
                Sseries.Format.Line.Visible = Office.MsoTriState.msoFalse;

                //if (comboBox_FourierMethod.SelectedItem.Equals("Circle"))
                //{
                Sseries.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleCircle;
                //}
                //else if (comboBox_FourierMethod.SelectedItem.Equals("Square"))
                //{
                //    Sseries.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleSquare;
                //}

                Sseries.MarkerBackgroundColor = System.Drawing.Color.FromArgb(255, RGB0.B, RGB0.G, RGB0.R).ToArgb();
                Sseries.MarkerForegroundColor = System.Drawing.Color.FromArgb(255, RGB0.B, RGB0.G, RGB0.R).ToArgb();

                Sseries.Format.Fill.Solid();
                Sseries.Format.Fill.Visible       = Office.MsoTriState.msoCTrue;
                Sseries.Format.Fill.BackColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb();
                Sseries.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, RGB0.B, RGB0.G, RGB0.R).ToArgb();
                Sseries.Format.Fill.Transparency  = 0.2F;

                //Sseries.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleCircle;

                for (j = 1; j < cols; j++)
                {
                    point = (Excel.Point)Sseries.Points(j);
                    //SquareSize = (int)((double.Parse(str[i, j])-Min_size) / (Max_size-Min_size) * ratio) + 2;
                    SquareSize = (int)((Math.Sqrt(double.Parse(str[i, j]) * ratio) / Max_size) * Min_MarkerSize + 2);   // - Min_size) / (Max_size - Min_size) * ratio) + 2;
                    //SquareSize = (int)((double.Parse(str[i, j]) / (Max_size * Max_size) * ratio) + 2);// - Min_size) / (Max_size - Min_size) * ratio) + 2;

                    if (SquareSize > 72)
                    {
                        SquareSize = 72;
                    }

                    point.MarkerSize = SquareSize;
                }
            }


            Excel.Series SseriesX = series.Item(rows);
            for (j = 1; j < cols; j++)
            {
                point = (Excel.Point)SseriesX.Points(j);
                point.HasDataLabel       = true;
                point.DataLabel.Text     = str[0, j];
                point.DataLabel.Position = Excel.XlDataLabelPosition.xlLabelPositionBelow;

                point.DataLabel.Format.TextFrame2.TextRange.Characters.Font.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
                point.DataLabel.Format.TextFrame2.TextRange.Font.NameComplexScript             = "Times New Roman";
                point.DataLabel.Format.TextFrame2.TextRange.Font.NameFarEast = "Times New Roman";
                point.DataLabel.Format.TextFrame2.TextRange.Font.Name        = "Times New Roman";
                point.DataLabel.Format.TextFrame2.TextRange.Font.Size        = 10;
                point.DataLabel.Format.TextFrame2.TextRange.Font.Bold        = Office.MsoTriState.msoFalse;
            }
            SseriesX.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleNone;

            Excel.Series SseriesY = series.Item(rows + 1);
            c1 = (Excel.Range)worksheet.Cells[start_row + rows + 1 + rows, start_col + +1];
            c2 = (Excel.Range)worksheet.Cells[start_row + rows + 1 + rows, start_col + rows - 1];
            SseriesY.XValues = worksheet.get_Range(c1, c2);

            c1 = (Excel.Range)worksheet.Cells[start_row + rows + 1 + rows + 1, start_col + 1];
            c2 = (Excel.Range)worksheet.Cells[start_row + rows + 1 + rows + 1, start_col + rows - 1];
            SseriesY.Values      = worksheet.get_Range(c1, c2);
            SseriesY.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleNone;

            for (j = 1; j < rows; j++)
            {
                point = (Excel.Point)SseriesY.Points(j);
                point.HasDataLabel       = true;
                point.DataLabel.Text     = str[j, 0];
                point.DataLabel.Position = Excel.XlDataLabelPosition.xlLabelPositionLeft;

                point.DataLabel.Format.TextFrame2.TextRange.Characters.Font.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
                point.DataLabel.Format.TextFrame2.TextRange.Font.NameComplexScript             = "Times New Roman";
                point.DataLabel.Format.TextFrame2.TextRange.Font.NameFarEast = "Times New Roman";
                point.DataLabel.Format.TextFrame2.TextRange.Font.Name        = "Times New Roman";
                point.DataLabel.Format.TextFrame2.TextRange.Font.Size        = 10;
                point.DataLabel.Format.TextFrame2.TextRange.Font.Bold        = Office.MsoTriState.msoFalse;
            }
            //***************************************************** Style**********************************************
            chart.PlotArea.Format.Fill.Visible       = Office.MsoTriState.msoCTrue;
            chart.PlotArea.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(229, 229, 229).ToArgb();
            chart.PlotArea.Format.Fill.Transparency  = 0;

            chart.PlotArea.Format.Line.Visible = Office.MsoTriState.msoFalse;

            // ChartArea Line
            chart.ChartArea.Format.Line.Visible = Office.MsoTriState.msoFalse;

            //chart.ChartArea.Height = 340.157480315;
            //chart.ChartArea.Width = 380.5039370079;

            // Chart Type: XYScatter
            // Add GridLinesMinorMajor
            chart.SetElement(Office.MsoChartElementType.msoElementPrimaryValueGridLinesMinorMajor);
            chart.SetElement(Office.MsoChartElementType.msoElementPrimaryCategoryGridLinesMinorMajor);
            chart.SetElement(Office.MsoChartElementType.msoElementPrimaryValueAxisTitleAdjacentToAxis);
            chart.SetElement(Office.MsoChartElementType.msoElementPrimaryCategoryAxisTitleAdjacentToAxis);

            //y axis
            Excel.Axis axis = (Excel.Axis)chart.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary);

            axis.MinorUnit = 1;
            axis.MajorUnit = 1;

            axis.MajorGridlines.Format.Line.Visible       = Office.MsoTriState.msoCTrue;
            axis.MajorGridlines.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255).ToArgb();
            axis.MajorGridlines.Format.Line.Weight        = (float)0.25;
            axis.MajorGridlines.Format.Line.DashStyle     = Office.MsoLineDashStyle.msoLineSolid;

            axis.MinorGridlines.Format.Line.Visible = Office.MsoTriState.msoFalse;
            //axis.MinorGridlines.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(242, 242, 242).ToArgb();
            //axis.MinorGridlines.Format.Line.Weight = (float)0.25;
            //axis.MinorGridlines.Format.Line.DashStyle = Office.MsoLineDashStyle.msoLineSolid;

            axis.Format.Line.Visible = Office.MsoTriState.msoFalse;
            axis.HasTitle            = true;
            axis.AxisTitle.Text      = "y axis";

            axis.HasDisplayUnitLabel = false;
            //axis.TickLabels.Font.Color = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
            //axis.TickLabels.Font.Name = "Times New Roman";
            //axis.TickLabels.Font.Size = 10;
            axis.TickLabelPosition = Excel.XlTickLabelPosition.xlTickLabelPositionNone;

            //axis.AxisTitle.Format.TextFrame2.TextRange.Characters.Font.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
            //axis.AxisTitle.Format.TextFrame2.TextRange.Font.NameComplexScript = "Times New Roman";
            //axis.AxisTitle.Format.TextFrame2.TextRange.Font.NameFarEast = "Times New Roman";
            //axis.AxisTitle.Format.TextFrame2.TextRange.Font.Name = "Times New Roman";
            //axis.AxisTitle.Format.TextFrame2.TextRange.Font.Size = 10;
            //axis.AxisTitle.Format.TextFrame2.TextRange.Font.Bold = Office.MsoTriState.msoFalse;


            //x axis
            axis = (Excel.Axis)chart.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary);

            axis.MaximumScale = cols;
            axis.MinimumScale = 0;
            //axis.AxisBetweenCategories = false;
            axis.MinorUnit = 1;
            axis.MajorUnit = 1;

            axis.MinorGridlines.Format.Line.Visible = Office.MsoTriState.msoFalse;
            //axis.MajorGridlines.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255).ToArgb();
            //axis.MajorGridlines.Format.Line.Weight = (float)1.25;
            //axis.MajorGridlines.Format.Line.DashStyle = Microsoft.Office.Core.MsoLineDashStyle.msoLineSolid;

            axis.MajorGridlines.Format.Line.Visible       = Office.MsoTriState.msoCTrue;
            axis.MajorGridlines.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255).ToArgb();
            axis.MajorGridlines.Format.Line.Weight        = (float)0.25;
            axis.MajorGridlines.Format.Line.DashStyle     = Office.MsoLineDashStyle.msoLineSolid;

            axis.Format.Line.Visible = Office.MsoTriState.msoFalse;

            axis.HasTitle       = true;
            axis.AxisTitle.Text = "x axis";


            //axis.TickLabels.Font.Color = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
            //axis.TickLabels.Font.Name = "Times New Roman";
            //axis.TickLabels.Font.Size = 10;
            axis.TickLabelPosition = Excel.XlTickLabelPosition.xlTickLabelPositionNone;

            //axis.AxisTitle.Format.TextFrame2.TextRange.Characters.Font.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
            //axis.AxisTitle.Format.TextFrame2.TextRange.Font.NameComplexScript = "Times New Roman";
            //axis.AxisTitle.Format.TextFrame2.TextRange.Font.NameFarEast = "Times New Roman";
            //axis.AxisTitle.Format.TextFrame2.TextRange.Font.Name = "Times New Roman";
            //axis.AxisTitle.Format.TextFrame2.TextRange.Font.Size = 10;
            //axis.AxisTitle.Format.TextFrame2.TextRange.Font.Bold = Office.MsoTriState.msoFalse;

            chart.HasLegend = false;
            chart.HasTitle  = false;
            //chart.ChartTitle.Delete();
            chart.Refresh();
            //worksheet.Activate();
        }
Example #10
0
        /*'***************************************************************
         * 'FFT0 数组下标以0开始  FFT1 数组下标以1开始
         * 'AR() 数据实部     AI() 数据虚部
         * 'N 数据点数,为2的整数次幂
         * 'NI 变换方向 1为正变换,-1为反变换
         * '*************************************************************** */

        private void Form_Fourier_Load(object sender, EventArgs e)
        {
            Graphic.RangeData(ref str, ref rows, ref cols);

            worksheet = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);
            Excel.Range activecells = Globals.ThisAddIn.Application.ActiveCell;
            start_col = activecells.Column;
            start_row = activecells.Row;

            //double[] FFTProjectionArray = new double[rows - 1];
            double[,] NewFFTProjectionArray = new double[rows - 1, 1];  //store the projection curve of FFT

            double TwoTime   = 0;
            double TwoResult = rows - 1;

            while (TwoResult > 1)
            {
                TwoResult = TwoResult / 2;
                TwoTime   = TwoTime + 1;
            }
            Nrows = Convert.ToInt32(Math.Pow(2.0, TwoTime));
            double[] AR = new double[Nrows];
            //double[] NewAR = new double[Nrows];

            for (int j = 1; j < rows; j++)
            {
                //FFTProjectionArray[j - 1] = double.Parse(str[j, 1]);
                AR[j - 1] = double.Parse(str[j, 1]);
            }

            double[] AI = new double[Nrows];
            FFT0(ref AR, ref AI, Nrows, 1);

            Span = double.Parse(textBox_Bandwidth.Text);

            comboBox_FourierMethod.Text = "Low Pass";

            for (int j = Convert.ToInt32(rows * Span) + 1; j < Nrows; j++)
            {
                AR[j] = 0;
                AI[j] = 0;
            }

            FFT0(ref AR, ref AI, Nrows, -1);
            for (int j = 1; j < rows; j++)
            {
                NewFFTProjectionArray[j - 1, 0] = AR[j - 1];
            }

            ((Excel.Range)worksheet.Cells[start_row, start_col + cols]).Value2 = "Smooth Y";
            Excel.Range c1    = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols];
            Excel.Range c2    = (Excel.Range)worksheet.Cells[start_row + 1 + rows - 2, start_col + cols];
            Excel.Range range = worksheet.get_Range(c1, c2);
            range.Value = NewFFTProjectionArray;

            //*******************************************************************************************8
            c1 = (Excel.Range)worksheet.Cells[start_row, start_col];
            c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols];

            string ChartOrder = "CurveFourier" + Convert.ToString(Nchart);

            chart  = worksheet.Controls.AddChart(250, 50, 450, 400, ChartOrder);
            Nchart = Nchart + 1;

            chart.SetSourceData(worksheet.get_Range(c1, c2), Excel.XlRowCol.xlColumns);
            chart.ChartType = Excel.XlChartType.xlXYScatter;

            Excel.SeriesCollection series = (Excel.SeriesCollection)chart.SeriesCollection();

            Excel.Series Sseries2 = series.Item(2);
            Sseries2.Format.Line.Visible = Office.MsoTriState.msoFalse;
            Sseries2.Format.Fill.Solid();
            Sseries2.Format.Fill.Visible = Office.MsoTriState.msoCTrue;
            //Sseries2.Format.Fill.BackColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb();
            //Sseries2.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255,229, 184,0).ToArgb();
            //Sseries2.Format.Fill.Transparency = 0.6F;

            Sseries2.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleCircle;
            Sseries2.MarkerSize  = 6;

            Excel.Series Sseries3 = series.Item(3);
            Sseries3.Format.Fill.Visible = Office.MsoTriState.msoFalse;
            Sseries3.Format.Line.Visible = Office.MsoTriState.msoTrue;
            Sseries3.MarkerStyle         = Excel.XlMarkerStyle.xlMarkerStyleNone;
            //Sseries3.Format.Line.ForeColor.RGB= System.Drawing.Color.FromArgb(255, 248, 118, 109).ToArgb();
            Sseries3.Format.Line.Weight = 1.25F;

            Excel.Series Sseries1 = series.Item(1);
            Sseries1.Delete();
        }
Example #11
0
        private void textBox_Bandwidth_TextChanged(object sender, EventArgs e)
        {
            if (textBox_Bandwidth.Text == "")
            {
                return;
            }
            Span = double.Parse(textBox_Bandwidth.Text);
            if (Span < 0 | Span > 1)
            {
                return;
            }


            double[,] NewFFTProjectionArray = new double[rows - 1, 1];  //store the projection curve of FFT
            double[] AR = new double[Nrows];
            //double[] NewAR = new double[Nrows];

            for (int j = 1; j < rows; j++)
            {
                //FFTProjectionArray[j - 1] = double.Parse(str[j, 1]);
                AR[j - 1] = double.Parse(str[j, 1]);
            }

            double[] AI = new double[Nrows];
            FFT0(ref AR, ref AI, Nrows, 1);

            if (comboBox_FourierMethod.SelectedItem.Equals("Low Pass"))
            {
                for (int j = Convert.ToInt32(rows * Span); j < Nrows; j++)
                {
                    AR[j] = 0;
                    AI[j] = 0;
                }
            }
            else if (comboBox_FourierMethod.SelectedItem.Equals("High Pass"))
            {
                for (int j = 0; j < Convert.ToInt32(rows * Span); j++)
                {
                    AR[j] = 0;
                    AI[j] = 0;
                }
            }
            else if (comboBox_FourierMethod.SelectedItem.Equals("Band Pass"))
            {
                for (int j = 0; j < Convert.ToInt32(rows * Span) + 1; j++)
                {
                    AR[j] = 0;
                    AI[j] = 0;
                }
                for (int j = Convert.ToInt32(rows * (1 - Span)); j < Nrows; j++)
                {
                    AR[j] = 0;
                    AI[j] = 0;
                }
            }
            else if (comboBox_FourierMethod.SelectedItem.Equals("Band Block"))
            {
                for (int j = Convert.ToInt32(rows * Span); j < Convert.ToInt32(rows * (1 - Span)) + 1; j++)
                {
                    AR[j] = 0;
                    AI[j] = 0;
                }
            }

            FFT0(ref AR, ref AI, Nrows, -1);
            for (int j = 1; j < rows; j++)
            {
                NewFFTProjectionArray[j - 1, 0] = AR[j - 1];
            }

            ((Excel.Range)worksheet.Cells[start_row, start_col + cols]).Value2 = "Smooth Y";
            Excel.Range c1    = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols];
            Excel.Range c2    = (Excel.Range)worksheet.Cells[start_row + 1 + rows - 2, start_col + cols];
            Excel.Range range = worksheet.get_Range(c1, c2);
            range.Value = NewFFTProjectionArray;
        }
Example #12
0
        public AreaThreshold()
        {
            InitializeComponent();

            Graphic.RangeData(ref str, ref rows, ref cols);

            worksheet = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);

            Excel.Range activecells = Globals.ThisAddIn.Application.ActiveCell;
            start_col = activecells.Column;
            start_row = activecells.Row;

            double Max_Value = Double.MinValue;
            double Min_Value = Double.MaxValue;

            for (int i = 1; i < rows; i++)
            {
                if (double.Parse(str[i, 0]) > Max_Value)
                {
                    Max_Value = double.Parse(str[i, 1]);
                }
                if (double.Parse(str[i, 0]) < Min_Value)
                {
                    Min_Value = double.Parse(str[i, 1]);
                }
            }
            ThreholdArea           = (Max_Value + Min_Value) / 2;
            textBox_Bandwidth.Text = Convert.ToString(ThreholdArea);
            textBox_Bandwidth.Refresh();


            ((Excel.Range)worksheet.Cells[start_row, start_col + cols + 1]).Value2 = "Assiatant";

            ((Excel.Range)worksheet.Cells[start_row, start_col + cols + 2]).Value2 = "<=Threshold";
            ((Excel.Range)worksheet.Cells[start_row, start_col + cols + 3]).Value2 = ">Threshold";

            double[,] data = new double[rows - 1, 3];
            for (int i = 1; i < rows; i++)
            {
                if (double.Parse(str[i, 1]) > ThreholdArea)
                {
                    data[i - 1, 2] = double.Parse(str[i, 1]) - ThreholdArea;
                    data[i - 1, 1] = 0;
                    data[i - 1, 0] = ThreholdArea - data[i - 1, 1];
                }
                else
                {
                    data[i - 1, 2] = 0;
                    data[i - 1, 1] = ThreholdArea - double.Parse(str[i, 1]);
                    data[i - 1, 0] = ThreholdArea - data[i - 1, 1];
                }
            }

            //double Max_data = Double.MinValue;
            //double Min_data = Double.MaxValue;
            //for (int i = 1; i < rows; i++)
            //{
            //    if (data[i - 1, 0] > Max_data) Max_data = data[i - 1, 0];
            //    if (data[i - 1, 1] < Min_data) Min_data = data[i - 1, 1];
            //}

            Excel.Range c1    = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 1];
            Excel.Range c2    = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols + 3];
            Excel.Range range = worksheet.get_Range(c1, c2);
            range.Value = data;

            string ChartOrder = "AreaThreshold" + Convert.ToString(Nchart);

            chart  = worksheet.Controls.AddChart(300, 50, 450, 400, ChartOrder);
            Nchart = Nchart + 1;

            c1 = (Excel.Range)worksheet.Cells[start_row, start_col + cols + 1];
            c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols + 3];
            chart.SetSourceData(worksheet.get_Range(c1, c2), Excel.XlRowCol.xlColumns);
            chart.ChartType = Excel.XlChartType.xlAreaStacked;

            //*****************************************Primary Axis********************************************
            Excel.SeriesCollection series   = (Excel.SeriesCollection)chart.SeriesCollection();
            Excel.Series           Sseries1 = series.Item(1);
            c1 = (Excel.Range)worksheet.Cells[start_row + 1, start_col];
            c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col];
            Sseries1.XValues = worksheet.get_Range(c1, c2);

            //c1 = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 1];
            //c2 = (Excel.Range)worksheet.Cells[start_row + rows-1, start_col + cols + 1];
            //Sseries1.Values = worksheet.get_Range(c1, c2);

            //c1 = (Excel.Range)worksheet.Cells[start_row + 1, start_col];
            //c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col];
            //Sseries2.XValues = worksheet.get_Range(c1, c2);

            //c1 = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 2];
            //c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols + 2];
            //Sseries2.Values = worksheet.get_Range(c1, c2);


            ((Excel.Range)worksheet.Cells[start_row, start_col + cols]).Value2     = "Threshold";
            ((Excel.Range)worksheet.Cells[start_row + 1, start_col + cols]).Value2 = ThreholdArea;


            //*****************************************Chart Style********************************************
            //Excel.Series Sseries1 = series.Item(1);
            Sseries1.Format.Fill.Visible = Office.MsoTriState.msoFalse;
            Sseries1.Format.Line.Visible = Office.MsoTriState.msoFalse;

            Excel.Series Sseries2 = series.Item(2);

            Sseries2.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 196, 191, 0).ToArgb();
            Sseries2.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 0, 0, 0).ToArgb();
            Sseries2.Format.Line.Weight        = 0.25F;


            Excel.Series Sseries3 = series.Item(3);
            Sseries3.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 109, 118, 248).ToArgb();
            Sseries3.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 0, 0, 0).ToArgb();
            Sseries3.Format.Line.Weight        = 0.25F;


            //************************************************************************************************
            chart.PlotArea.Format.Fill.Visible       = Office.MsoTriState.msoCTrue;
            chart.PlotArea.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(229, 229, 229).ToArgb();
            chart.PlotArea.Format.Fill.Transparency  = 0;

            chart.PlotArea.Format.Line.Visible = Office.MsoTriState.msoFalse;

            // Legend
            chart.SetElement(Office.MsoChartElementType.msoElementLegendRight);
            chart.Legend.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
            chart.Legend.Format.TextFrame2.TextRange.Font.NameComplexScript  = "Times New Roman";
            chart.Legend.Format.TextFrame2.TextRange.Font.NameFarEast        = "Times New Roman";
            chart.Legend.Format.TextFrame2.TextRange.Font.Name = "Times New Roman";
            chart.Legend.Format.TextFrame2.TextRange.Font.Size = 10;

            // ChartArea Line
            chart.ChartArea.Format.Line.Visible = Office.MsoTriState.msoFalse;

            chart.ChartArea.Height = 340.157480315;
            chart.ChartArea.Width  = 380.5039370079;

            chart.SetElement(Office.MsoChartElementType.msoElementPrimaryValueGridLinesMinorMajor);
            chart.SetElement(Office.MsoChartElementType.msoElementPrimaryCategoryGridLinesMinorMajor);
            chart.SetElement(Office.MsoChartElementType.msoElementPrimaryValueAxisTitleAdjacentToAxis);
            chart.SetElement(Office.MsoChartElementType.msoElementPrimaryCategoryAxisTitleAdjacentToAxis);

            //y axis
            Excel.Axis axis = (Excel.Axis)chart.Axes(
                Excel.XlAxisType.xlValue,
                Excel.XlAxisGroup.xlPrimary);

            axis.MinorUnit = axis.MajorUnit / 2;
            axis.MajorGridlines.Format.Line.Visible       = Office.MsoTriState.msoCTrue;
            axis.MajorGridlines.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255).ToArgb();
            axis.MajorGridlines.Format.Line.Weight        = (float)1.25;
            axis.MajorGridlines.Format.Line.DashStyle     = Office.MsoLineDashStyle.msoLineSolid;

            axis.MinorGridlines.Format.Line.Visible       = Office.MsoTriState.msoCTrue;
            axis.MinorGridlines.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(242, 242, 242).ToArgb();
            axis.MinorGridlines.Format.Line.Weight        = (float)0.25;
            axis.MinorGridlines.Format.Line.DashStyle     = Office.MsoLineDashStyle.msoLineSolid;

            axis.Format.Line.Visible = Office.MsoTriState.msoFalse;
            axis.HasTitle            = true;
            axis.AxisTitle.Text      = "y axis";

            axis.TickLabels.Font.Color = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
            axis.TickLabels.Font.Name  = "Times New Roman";
            axis.TickLabels.Font.Size  = 10;
            axis.TickLabelPosition     = Excel.XlTickLabelPosition.xlTickLabelPositionLow;

            axis.AxisTitle.Format.TextFrame2.TextRange.Characters.Font.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
            axis.AxisTitle.Format.TextFrame2.TextRange.Font.NameComplexScript             = "Times New Roman";
            axis.AxisTitle.Format.TextFrame2.TextRange.Font.NameFarEast = "Times New Roman";
            axis.AxisTitle.Format.TextFrame2.TextRange.Font.Name        = "Times New Roman";
            axis.AxisTitle.Format.TextFrame2.TextRange.Font.Size        = 10;
            axis.AxisTitle.Format.TextFrame2.TextRange.Font.Bold        = Office.MsoTriState.msoFalse;


            //x axis
            axis = (Excel.Axis)chart.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary);
            axis.TickMarkSpacing = 3;

            axis.MajorGridlines.Format.Line.Visible       = Office.MsoTriState.msoCTrue;
            axis.MajorGridlines.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255).ToArgb();
            axis.MajorGridlines.Format.Line.Weight        = (float)1.25;
            axis.MajorGridlines.Format.Line.DashStyle     = Office.MsoLineDashStyle.msoLineSolid;

            axis.MinorGridlines.Format.Line.Visible       = Office.MsoTriState.msoCTrue;
            axis.MinorGridlines.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(242, 242, 242).ToArgb();
            axis.MinorGridlines.Format.Line.Weight        = (float)0.25;
            axis.MinorGridlines.Format.Line.DashStyle     = Office.MsoLineDashStyle.msoLineSolid;

            axis.Format.Line.Visible = Office.MsoTriState.msoFalse;

            axis.HasTitle       = true;
            axis.AxisTitle.Text = "x axis";

            axis.TickLabels.Font.Color = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
            axis.TickLabels.Font.Name  = "Times New Roman";
            axis.TickLabels.Font.Size  = 10;
            axis.TickLabelPosition     = Excel.XlTickLabelPosition.xlTickLabelPositionLow;

            axis.AxisTitle.Format.TextFrame2.TextRange.Characters.Font.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
            axis.AxisTitle.Format.TextFrame2.TextRange.Font.NameComplexScript             = "Times New Roman";
            axis.AxisTitle.Format.TextFrame2.TextRange.Font.NameFarEast = "Times New Roman";
            axis.AxisTitle.Format.TextFrame2.TextRange.Font.Name        = "Times New Roman";
            axis.AxisTitle.Format.TextFrame2.TextRange.Font.Size        = 10;
            axis.AxisTitle.Format.TextFrame2.TextRange.Font.Bold        = Office.MsoTriState.msoFalse;
            // Change plot area ForeColor

            chart.HasLegend = false;
            chart.HasTitle  = false;

            chart.Refresh();
            //worksheet.Activate();
            flag = 1;
        }
Example #13
0
        public DensityScatter()
        {
            InitializeComponent();

            //hScrollBar_Parameter1.Value = 2;
            //Graphics Graphic = new Graphics();
            Bandwidth = double.Parse(textBox_Bandwidth.Text);
            //if (Form_Parater.flag == 0) return;
            //int rows = 1;
            //int cols = 1;
            //string[,] str = new string[1, 1];
            Graphic.RangeData(ref str, ref rows, ref cols);

            worksheet = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);

            Excel.Range activecells = Globals.ThisAddIn.Application.ActiveCell;
            start_col = activecells.Column;
            start_row = activecells.Row;

            int i;

            ((Excel.Range)worksheet.Cells[start_row, start_col + cols]).Value2     = "X-axis Value";
            ((Excel.Range)worksheet.Cells[start_row, start_col + cols + 1]).Value2 = "Y-axis Value";

            double Pdensity = Bandwidth * 100;
            double Maxtemp  = 1000;

            double[,] data = new double[rows, 2];
            for (i = 1; i < rows; i++)
            {
                data[i - 1, 0] = Math.Floor(double.Parse(str[i, 0]) * Maxtemp / Pdensity) * Pdensity / Maxtemp;
                data[i - 1, 1] = Math.Floor(double.Parse(str[i, 1]) * Maxtemp / Pdensity) * Pdensity / Maxtemp;
                //((Excel.Range)worksheet.Cells[start_row + i, start_col + cols]).Value2 = Math.Floor(double.Parse(str[i, 0]) * Maxtemp / Pdensity) * Pdensity / Maxtemp;
                //((Excel.Range)worksheet.Cells[start_row + i, start_col + cols + 1]).Value2 = Math.Floor(double.Parse(str[i, 1]) * Maxtemp / Pdensity) * Pdensity / Maxtemp;
            }

            Excel.Range c1    = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols];
            Excel.Range c2    = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols + cols - 1];
            Excel.Range range = worksheet.get_Range(c1, c2);
            range.Value = data;

            string ChartOrder = "DensityScatter" + Convert.ToString(Nchart);

            chart  = worksheet.Controls.AddChart(250, 50, 450, 400, ChartOrder);
            Nchart = Nchart + 1;

            c1 = (Excel.Range)worksheet.Cells[start_row, start_col + cols];
            c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols + cols - 1];
            chart.SetSourceData(worksheet.get_Range(c1, c2), Excel.XlRowCol.xlColumns);
            chart.ChartType = Excel.XlChartType.xlXYScatter;

            Excel.SeriesCollection series = (Excel.SeriesCollection)chart.SeriesCollection();

            if (series.Count == 2)
            {
                Excel.Series Sseries2 = series.Item(2);
                Sseries2.Delete();
            }

            Excel.Series Sseries = series.Item(1);
            c1 = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols];
            c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols];
            Sseries.XValues = worksheet.get_Range(c1, c2);

            c1             = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 1];
            c2             = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols + 1];
            Sseries.Values = worksheet.get_Range(c1, c2);

            Sseries.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleCircle;
            //Sseries.Format.Line.Visible = Office.MsoTriState.msoFalse;

            Sseries.MarkerSize            = 5;
            Sseries.MarkerBackgroundColor = System.Drawing.Color.FromArgb(255, 109, 118, 248).ToArgb();
            Sseries.MarkerForegroundColor = System.Drawing.Color.FromArgb(255, 109, 118, 248).ToArgb();
            //Sseries.Format.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;

            Sseries.Format.Fill.Solid();
            Sseries.Format.Fill.Visible       = Office.MsoTriState.msoCTrue;
            Sseries.Format.Fill.BackColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb();
            Sseries.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 109, 118, 248).ToArgb();
            Sseries.Format.Fill.Transparency  = 0.9F;

            worksheet.Activate();
        }
Example #14
0
        public BubbleSquare()
        {
            InitializeComponent();
            ratio = double.Parse(textBox_Bandwidth.Text);
            Graphic.RangeData(ref str, ref rows, ref cols);

            worksheet = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);

            Excel.Range activecells = Globals.ThisAddIn.Application.ActiveCell;
            start_col = activecells.Column;
            start_row = activecells.Row;

            Excel.Range c1 = (Excel.Range)worksheet.Cells[start_row, start_col];
            Excel.Range c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + 1];

            string ChartOrder = "SquareBubble" + Convert.ToString(Nchart);

            chart  = worksheet.Controls.AddChart(250, 50, 450, 400, ChartOrder);
            Nchart = Nchart + 1;

            chart.SetSourceData(worksheet.get_Range(c1, c2), Excel.XlRowCol.xlColumns);

            chart.ChartType = Excel.XlChartType.xlXYScatter;

            Excel.SeriesCollection series = (Excel.SeriesCollection)chart.SeriesCollection();

            if (series.Count == 2)
            {
                Excel.Series Sseries2 = series.Item(2);
                Sseries2.Delete();
            }

            Excel.Series Sseries = series.Item(1);
            c1 = (Excel.Range)worksheet.Cells[start_row + 1, start_col];
            c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col];
            Sseries.XValues = worksheet.get_Range(c1, c2);

            c1             = (Excel.Range)worksheet.Cells[start_row + 1, start_col + 1];
            c2             = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + 1];
            Sseries.Values = worksheet.get_Range(c1, c2);

            Excel.Point point;
            //double ratio = 42;
            int SquareSize;

            //((Excel.Range)worksheet.Cells[Graphic.start_row, Graphic.start_col + 3]).Value2 = "Square Size";

            Max_size = Double.MinValue;
            Min_size = Double.MaxValue;
            int i;

            for (i = 1; i < rows; i++)
            {
                if (double.Parse(str[i, 2]) > Max_size)
                {
                    Max_size = double.Parse(str[i, 2]);
                }
                if (double.Parse(str[i, 2]) < Min_size)
                {
                    Min_size = double.Parse(str[i, 2]);
                }
            }

            Max_size = Math.Sqrt(Max_size);
            Min_size = Math.Sqrt(Min_size);
            //int[,] PointSize = new int[Graphic.rows - 1, 1];
            for (i = 1; i < rows; i++)
            {
                point = (Excel.Point)Sseries.Points(i);
                //SquareSize = (int)((Math.Sqrt(double.Parse(str[i, 2])) - Min_size));// / (Max_size-Min_size) * ratio) + 2;
                SquareSize = (int)((Math.Sqrt(double.Parse(str[i, 2])) / Max_size * ratio) + 2);
                //PointSize[i - 1, 0] = SquareSize;
                //((Excel.Range)worksheet.Cells[Graphic.start_row + i, Graphic.start_col + 3]).Value2 = SquareSize;
                point.MarkerSize = SquareSize;
            }


            Sseries.MarkerBackgroundColor = System.Drawing.Color.FromArgb(255, 77, 175, 74).ToArgb();
            Sseries.MarkerForegroundColor = System.Drawing.Color.FromArgb(255, 77, 175, 74).ToArgb();

            Sseries.Format.Fill.Solid();
            Sseries.Format.Fill.Visible       = Office.MsoTriState.msoCTrue;
            Sseries.Format.Fill.BackColor.RGB = System.Drawing.Color.FromArgb(255, 229, 229, 229).ToArgb();
            Sseries.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 77, 175, 74).ToArgb();
            Sseries.Format.Fill.Transparency  = 0.3F;

            Sseries.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleSquare;

            //Rggplot2();
            chart.HasLegend = false;
            chart.HasTitle  = false;
            //chart.ChartTitle.Delete();
            worksheet.Activate();
        }