Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            colorDialog1.ShowDialog();
            RGB0 = colorDialog1.Color;

            button_ColorSelection.BackColor = RGB0;
            button_ColorSelection.ForeColor = RGB0;

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

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

            //RGB0 = System.Drawing.Color.FromArgb(255, 109, 118, 248);
            for (int i = 1; i < rows; i++)
            {
                Sseries = series.Item(i);
                Sseries.Format.Line.Visible   = Office.MsoTriState.msoFalse;
                Sseries.MarkerStyle           = Excel.XlMarkerStyle.xlMarkerStyleCircle;
                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;

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

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

                    point.MarkerSize = SquareSize;
                }
            }
            chart.Refresh();
            worksheet.Activate();
        }
Exemplo n.º 2
0
        private void textBox_Bandwidth_TextChanged(object sender, EventArgs e)
        {
            if (textBox_Bandwidth.Text == "")
            {
                return;
            }
            Hrange = double.Parse(textBox_Bandwidth.Text);
            if (Hrange == 0)
            {
                return;
            }

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

            Excel.Series Sseries = series.Item(1);

            Excel.Point          point;
            System.Drawing.Color RGB1 = System.Drawing.Color.FromArgb(255, 96, 157, 202);
            int[] HSV0 = new int[3];

            Graphic.RGB2HSV(RGB0, ref HSV0);

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

            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;
            }

            chart.Refresh();
            worksheet.Activate();
        }
Exemplo n.º 3
0
        private void textBox_Bandwidth_TextChanged(object sender, EventArgs e)
        {
            if (textBox_Bandwidth.Text == "")
            {
                return;
            }
            ratio = double.Parse(textBox_Bandwidth.Text);;
            if (ratio == 0)
            {
                return;
            }

            Excel.SeriesCollection series  = (Excel.SeriesCollection)chart.SeriesCollection();
            Excel.Series           Sseries = series.Item(1);

            Excel.Point point;
            int         SquareSize;

            for (int 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);
                //point = (Excel.Point)Sseries.Points(i);
                //SquareSize = (int)((double.Parse(str[i, 2]) - Min_size) / (Max_size - Min_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;

            chart.Refresh();
            worksheet.Activate();
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 7
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();
        }
Exemplo n.º 8
0
        public Form_Cofficient()
        {
            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;

            double[,] Mat_Cofficent = new double[cols, cols];
            double[] temp1 = new double [rows - 1];
            double[] temp2 = new double [rows - 1];

            int i, j;

            for (i = 0; i < cols; i++)
            {
                Mat_Cofficent[i, i] = 1;

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

                for (int k = i + 1; k < cols; k++)
                {
                    for (j = 1; j < rows; j++)
                    {
                        temp2[j - 1] = double.Parse(str[j, k]);
                    }

                    Mat_Cofficent[i, k] = GetCorrelation(temp1, temp2);
                    Mat_Cofficent[k, i] = Mat_Cofficent[i, k];
                }
            }

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

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


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

            //****************************************************************************************************
            ratio = double.Parse(textBox_Bandwidth.Text);;
            str   = new string[cols + 1, cols + 1];
            for (i = 0; i <= cols; i++)
            {
                for (j = 0; j <= cols; j++)
                {
                    str[i, j] = Convert.ToString(((Excel.Range)worksheet.Cells[start_row + rows + 1 + i, start_col + j]).Value2);
                }
            }
            // Graphic.RangeData(ref str, ref rows, ref cols);
            start_row = start_row + rows + 1;

            rows = cols + 1;
            cols = cols + 1;
            //worksheet = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);

            //activecells = Globals.ThisAddIn.Application.ActiveCell;
            //start_col = activecells.Column;


            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;
            }


            c1 = (Excel.Range)worksheet.Cells[start_row + rows + 1, start_col];
            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, 300, 300, 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]);
            //    }
            //}
            Excel.SeriesCollection series = (Excel.SeriesCollection)chart.SeriesCollection();

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

            RGB0 = System.Drawing.Color.FromArgb(255, 248, 118, 109);
            RGB1 = System.Drawing.Color.FromArgb(255, 0, 184, 229);
            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.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleCircle;

                for (j = 1; j < cols; j++)
                {
                    point = (Excel.Point)Sseries.Points(j);

                    if (double.Parse(str[i, j]) >= 0)
                    {
                        point.MarkerBackgroundColor = System.Drawing.Color.FromArgb(255, RGB0.B, RGB0.G, RGB0.R).ToArgb();
                        point.MarkerForegroundColor = System.Drawing.Color.FromArgb(255, RGB0.B, RGB0.G, RGB0.R).ToArgb();

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

                    else
                    {
                        point.MarkerBackgroundColor = System.Drawing.Color.FromArgb(255, RGB1.B, RGB1.G, RGB1.R).ToArgb();
                        point.MarkerForegroundColor = System.Drawing.Color.FromArgb(255, RGB1.B, RGB1.G, RGB1.R).ToArgb();

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

                    // SquareSize = (int)((double.Parse(str[i, j]) - Min_size) / (Max_size - Min_size) * ratio) + 2;
                    if (i == j)
                    {
                        SquareSize       = 2;
                        point.MarkerSize = SquareSize;
                    }
                    else
                    {
                        SquareSize = (int)(Math.Sqrt(Math.Abs((double.Parse(str[i, j])))) * 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;

                point.DataLabel.Format.TextFrame2.Orientation = Office.MsoTextOrientation.msoTextOrientationUpward;
            }
            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();
            worksheet.Activate();
        }
Exemplo n.º 9
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();
        }
Exemplo n.º 10
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();
        }