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(); }
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(); }
public Form_Color_Matrix() { InitializeComponent(); height = int.Parse(textBox_height.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 width = (int)Math.Ceiling(Convert.ToDouble(rows) / Convert.ToDouble(height)); int[,] data = new int[height, width]; int[] temp = new int[width]; // for (int i = 0; i < height; i++) // { //temp = new int[width]; // for (int j = 0; j < width; j++) // { // // temp[j] = 1; // data[i, j] = 1; // ((range)worksheet.Cells[start_row + rows + 1 + i , start_col + j ]).Value2 = 1; // } //Sseries = series.NewSeries(); //Sseries.Values = temp; // } range c1 = (range)worksheet.Cells[start_row + rows + 1, start_col]; range c2 = (range)worksheet.Cells[start_row + rows + 1 + height - 1, start_col + width - 1]; string ChartOrder = "chart" + 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.xlColumnStacked100; Excel.ChartGroup group = (Excel.ChartGroup)chart.ChartGroups(1); group.GapWidth = 0; Excel.SeriesCollection series = (Excel.SeriesCollection)chart.SeriesCollection(); Excel.Series Sseries; Excel.Point point; int RGB_B, RGB_G, RGB_R; for (int i = 0; i < height; i++) { temp = new int[width]; for (int j = 0; j < width; j++) { temp[j] = 1; data[i, j] = 1; } Sseries = series.NewSeries(); Sseries.Values = temp; } for (int i = 1; i <= height; i++) { Sseries = series.Item(i); for (int j = 1; j <= width; j++) { { point = (Excel.Point)Sseries.Points(j); 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(); int index = (i - 1) * width + j; if (index < rows) { RGB_B = Convert.ToInt32(double.Parse(str[index, cols - 1])); if (RGB_B < 0) { RGB_B = 0; } if (RGB_B > 255) { RGB_B = 255; } RGB_G = Convert.ToInt32(double.Parse(str[index, cols - 2])); if (RGB_G < 0) { RGB_G = 0; } if (RGB_G > 255) { RGB_G = 255; } RGB_R = Convert.ToInt32(double.Parse(str[index, cols - 3])); if (RGB_R < 0) { RGB_R = 0; } if (RGB_R > 255) { RGB_R = 255; } point.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, RGB_B, RGB_G, RGB_R).ToArgb(); point.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 0, 0, 0).ToArgb(); } else { point.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb(); point.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb(); } } } } }
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.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; 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; for (int j = 1; j < cols; j++) { point = (Excel.Point)Sseries.Points(j); SquareSize = (int)((Math.Sqrt(double.Parse(str[i, j]) * ratio) / Max_size) * Min_MarkerSize + 2); //SquareSize = (int)((double.Parse(str[i, j]) - 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; } } chart.Refresh(); //worksheet.Activate(); }
private void button_OK_Click(object sender, EventArgs e) { height = int.Parse(textBox_height.Text); int width = (int)Math.Ceiling(Convert.ToDouble(rows) / Convert.ToDouble(height)); int[,] data = new int[height, width]; int[] temp = new int[width]; Excel.SeriesCollection series = (Excel.SeriesCollection)chart.SeriesCollection(); int N_Ser = series.Count; Excel.Series Sseries; if (N_Ser > height) { for (int i = N_Ser; i > height; i--) { series.Item(i).Delete(); } } else { for (int i = N_Ser + 1; i <= height; i++) { Sseries = series.NewSeries(); } } Excel.Point point; int RGB_B, RGB_G, RGB_R; for (int i = 0; i < height; i++) { temp = new int[width]; for (int j = 0; j < width; j++) { temp[j] = 1; data[i, j] = 1; } //Sseries = series.NewSeries(); series.Item(i + 1).Values = temp; } for (int i = 1; i <= height; i++) { Sseries = series.Item(i); for (int j = 1; j <= width; j++) { { point = (Excel.Point)Sseries.Points(j); 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(); int index = (i - 1) * width + j; if (index < rows) { RGB_B = Convert.ToInt32(double.Parse(str[index, cols - 1])); if (RGB_B < 0) { RGB_B = 0; } if (RGB_B > 255) { RGB_B = 255; } RGB_G = Convert.ToInt32(double.Parse(str[index, cols - 2])); if (RGB_G < 0) { RGB_G = 0; } if (RGB_G > 255) { RGB_G = 255; } RGB_R = Convert.ToInt32(double.Parse(str[index, cols - 3])); if (RGB_R < 0) { RGB_R = 0; } if (RGB_R > 255) { RGB_R = 255; } point.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, RGB_B, RGB_G, RGB_R).ToArgb(); point.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 0, 0, 0).ToArgb(); } else { point.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb(); point.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb(); } } } } }