forked from yaunqiying/EasyCharts
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDensityScatter.cs
149 lines (120 loc) · 6.52 KB
/
DensityScatter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using System;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Excel;
namespace ExcelAddIn_Graphics
{
public partial class DensityScatter: Form
{
public double Bandwidth;
//public int flag = 0;
public Chart chart;
public Microsoft.Office.Tools.Excel.Worksheet worksheet;
public string ChartType;
static int Nchart = 0;
EasyCharts Graphic =new EasyCharts();
public int rows = 1;
public int cols = 1;
public string[,] str = new string[1, 1];
public int start_col;
public int start_row;
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();
}
private void button_OK_Click(object sender, EventArgs e)
{
//this.Hide();
Close();
}
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();
}
}
}