forked from yaunqiying/EasyCharts
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathScatterColor.cs
205 lines (159 loc) · 7.69 KB
/
ScatterColor.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
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 ScatterColor : Form
{
public Chart chart;
public Microsoft.Office.Tools.Excel.Worksheet worksheet;
public string ChartType;
public System.Drawing.Color RGB0;
static int Nchart = 0;
public double Max_Value;
public double Min_Value;
EasyCharts Graphic = new EasyCharts();
public double Hrange;
public int rows = 1;
public int cols = 1;
public string[,] str = new string[1, 1];
public int start_col;
public int start_row;
public ScatterColor()
{
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 = "ColorScatter" + 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;
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, 2]);
if (double.Parse(str[i, 2]) < Min_Value) Min_Value = double.Parse(str[i, 2]);
}
int[] HSV = new int[3];
HSV0.CopyTo(HSV, 0);
double ratio;
Hrange = double.Parse(textBox_Bandwidth.Text);
//Sseries.MarkerBackgroundColor = RGB0.ToArgb();
//Sseries.MarkerForegroundColor = RGB0.ToArgb();
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;
//point.Format.Line.Visible = Microsoft.Office.Core.MsoTriState.msoCTrue;
//point.Format.Line.ForeColor.RGB = RGB0.ToArgb();
}
Sseries.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleCircle;
Sseries.MarkerSize = 8;
//Excel.ChartGroup group = (Excel.ChartGroup)chart.ChartGroups(1);
//group.GapWidth = 0;
chart.HasLegend = false;
chart.HasTitle = false;
//chart.ChartTitle.Delete();
chart.Refresh();
//worksheet.Activate();
}
private void button_OK_Click(object sender, EventArgs e)
{
Close();
}
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();
}
private void button_ColorSelection_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.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;
//double 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;
}
chart.Refresh();
//worksheet.Activate();
}
}
}