private void FormDemoChart_Load(object sender, EventArgs e) { //显示滚动条 this.AutoScroll = true; this.panel1.AutoScrollMinSize = new Size() { Width = 1181, Height = 723 }; this.VerticalScroll.Visible = true;//竖的 y = 0; this.VerticalScroll.Value = y; chart1.Series.Clear(); ChartHelper.AddSeries(chart1, "柱状图", SeriesChartType.Column, Color.Lime, Color.Red, true); ChartHelper.AddSeries(chart1, "曲线图", SeriesChartType.Spline, Color.Red, Color.Red); ChartHelper.SetTitle(chart1, "柱状图与曲线图", new Font("微软雅黑", 12), Docking.Bottom, Color.White); ChartHelper.SetStyle(chart1, Color.Transparent, Color.White); ChartHelper.SetLegend(chart1, Docking.Top, StringAlignment.Center, Color.Transparent, Color.White); ChartHelper.SetXY(chart1, "序号", "数值", StringAlignment.Far, Color.White, Color.White, AxisArrowStyle.SharpTriangle, 1, 2); ChartHelper.SetMajorGrid(chart1, Color.Gray, 20, 2); chart2.Series.Clear(); ChartHelper.AddSeries(chart2, "饼状图", SeriesChartType.Pie, Color.Lime, Color.Red, true); ChartHelper.SetStyle(chart2, Color.Transparent, Color.White); ChartHelper.SetLegend(chart2, Docking.Top, StringAlignment.Center, Color.Transparent, Color.White); chart3.Series.Clear(); ChartHelper.AddSeries(chart3, "曲线图", SeriesChartType.SplineRange, Color.FromArgb(100, 46, 199, 201), Color.Red, true); ChartHelper.SetTitle(chart3, "曲线图", new Font("微软雅黑", 12), Docking.Bottom, Color.FromArgb(46, 199, 201)); ChartHelper.SetStyle(chart3, Color.Transparent, Color.White); ChartHelper.SetLegend(chart3, Docking.Top, StringAlignment.Center, Color.Transparent, Color.White); ChartHelper.SetXY(chart3, "序号", "数值", StringAlignment.Far, Color.White, Color.White, AxisArrowStyle.SharpTriangle, 1, 2); ChartHelper.SetMajorGrid(chart3, Color.Gray, 20, 2); chart4.Series.Clear(); ChartHelper.AddSeries(chart4, "饼状图", SeriesChartType.Funnel, Color.Lime, Color.Red, true); ChartHelper.SetStyle(chart4, Color.Transparent, Color.White); ChartHelper.SetLegend(chart4, Docking.Top, StringAlignment.Center, Color.Transparent, Color.White); RefreshData(); }
private void Start_Click(object sender, EventArgs e) { //pictureBox2.Image = SandDiameterMeasuring.Properties.Resources.屏幕截图_1654_; // pictureBox2.Image.Dispose(); // pictureBox2.Image = null; textBox1.Text = ("加载图片"); OpenFileDialog file = new OpenFileDialog(); file.InitialDirectory = "."; file.Filter = "所有文件(*.*)|*.*"; file.ShowDialog(); if (file.FileName != string.Empty) { try { pathname = file.FileName; //获得文件的绝对路径 this.pictureBox1.Load(pathname); } catch (Exception ex) { MessageBox.Show(ex.Message); } } Stopwatch sw = new Stopwatch(); sw.Start(); string str1 = file.FileName; //str1 = "'" + str1 + "'";//加单引号为符合matlab输入规范 textBox1.Text = (str1); linktocsharpV6.Class1 v5c1 = new linktocsharpV6.Class1(); //MWArray DiameterArray = v3c1.linktocsharpV3(str1); MWArray[] resultlist = new MWArray[2]; resultlist = v5c1.linktocsharpV6(5, str1); //重要!!!m函数有多个返回值时在第一个参数里写入返回值个数,第二个参数才是输入m函数的第一个输入参数 MWNumericArray DiameterArray = (MWNumericArray)resultlist[0]; //返回每一粒沙子的直径数组,为n行1列的二维数组 MWNumericArray SandNumber = (MWNumericArray)resultlist[1]; //沙尘个数 MWNumericArray DiameterNumber = (MWNumericArray)resultlist[2]; //返回以50um为单位的粒径累加结果数组 MWNumericArray xlength = (MWNumericArray)resultlist[3]; //返回粒径累加结果数组长度 MWNumericArray TypeNumber = (MWNumericArray)resultlist[4]; //返回三种沙粒:石砾,粗沙粒,细沙粒个数数组 textBox2.Text = SandNumber.ToString(); double[,] DA = new double[(int)SandNumber, 1]; //matlab函数返回值为二维数组,因此需要用二维数组接收 DA = (double[, ])DiameterArray.ToArray(); double[,] DN = new double[(int)xlength, 1]; //matlab函数返回值为二维数组,因此需要用二维数组接收 DN = (double[, ])DiameterNumber.ToArray(); double[,] TN = new double[3, 1]; //matlab函数返回值为二维数组,因此需要用二维数组接收 TN = (double[, ])TypeNumber.ToArray(); //textBox3.Text = DA[(int)a2 - 1, 0].ToString(); //textBox3.Text = DA[(int)SandNumber - 1, 0].ToString(); chart1.Series.Clear(); ChartHelper.AddSeries(chart1, "由小到大每一粒沙尘的粒径", SeriesChartType.Column, Color.Transparent, Color.Red, true); // ChartHelper.AddSeries(chart1, "由小到大每一粒沙尘的粒径", SeriesChartType.Spline, Color.Red, Color.Red); // ChartHelper.SetTitle(chart1, "由小到大每一粒沙尘的粒径", new Font("微软雅黑", 8), Docking.Top, Color.Black); ChartHelper.SetStyle(chart1, Color.Transparent, Color.Black); ChartHelper.SetLegend(chart1, Docking.Top, StringAlignment.Center, Color.Transparent, Color.Black); ChartHelper.SetXY(chart1, "", "粒径(*50um)", StringAlignment.Far, Color.Black, Color.Black, AxisArrowStyle.SharpTriangle, 0, 0); ChartHelper.SetMajorGrid(chart1, Color.Transparent, 20, 50); List <int> xData = new List <int>() { }; int i, j; for (i = 1; i <= (int)SandNumber; i++) { xData.Add(i); } List <double> yData = new List <double>() { }; for (j = 0; j <= (int)SandNumber - 1; j++) { yData.Add(DA[j, 0]); } chart1.Series[0].Points.DataBindXY(xData, yData); chart2.Series.Clear(); ChartHelper.AddSeries(chart2, "该粒径范围内沙尘个数", SeriesChartType.Column, Color.Lime, Color.Blue, true); // ChartHelper.AddSeries(chart2, "曲线图", SeriesChartType.Spline, Color.Red, Color.Red); // ChartHelper.SetTitle(chart2, "柱状图与曲线图", new Font("微软雅黑", 12), Docking.Bottom, Color.Black); ChartHelper.SetStyle(chart2, Color.Transparent, Color.Black); ChartHelper.SetLegend(chart2, Docking.Top, StringAlignment.Center, Color.Transparent, Color.Black); ChartHelper.SetXY(chart2, "粒径(*50um)", "个数", StringAlignment.Far, Color.Black, Color.Black, AxisArrowStyle.SharpTriangle, 4, (int)(DN[0, 0] / 10)); ChartHelper.SetMajorGrid(chart2, Color.Transparent, 20, 2); List <int> xData2 = new List <int>() { }; int i2, j2; for (i2 = 1; i2 <= (int)xlength; i2++) { xData2.Add(i2); } List <double> yData2 = new List <double>() { }; for (j2 = 0; j2 <= (int)xlength - 1; j2++) { yData2.Add(DN[j2, 0]); } chart2.Series[0].Points.DataBindXY(xData2, yData2); chart3.Series.Clear(); ChartHelper.AddSeries(chart3, "饼状图", SeriesChartType.Pie, Color.Lime, Color.Black, true); ChartHelper.SetStyle(chart3, Color.Transparent, Color.Black); ChartHelper.SetLegend(chart3, Docking.Bottom, StringAlignment.Center, Color.Transparent, Color.Black); List <double> y1 = new List <double>() { }; int j3; for (j3 = 0; j3 <= 2; j3++) { y1.Add(TN[j3, 0]); } string t1 = String.Format("石砾(>1000㎛): {0}个", TN[0, 0]); string t2 = String.Format("粗沙粒(250-1000㎛): {0}个", TN[1, 0]); string t3 = String.Format("细沙粒(50-250㎛): {0}个", TN[2, 0]); List <string> nameX = new List <string>() { t1, t2, t3 }; chart3.Series[0].Points.DataBindXY(nameX, y1); chart3.Series[0]["PieLabelStyle"] = "Outside"; //将文字移到外侧 chart3.Series[0]["PieLineColor"] = "Black"; //绘制黑色的连线。 chart3.Series[0].Label = "#PERCENT{P2}"; sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine("DateTime costed for this function is: {0}ms", ts.TotalMilliseconds); }
private void Start_Click(object sender, EventArgs e) { //pictureBox2.Image = SandDiameterMeasuring.Properties.Resources.屏幕截图_1654_; // pictureBox2.Image.Dispose(); // pictureBox2.Image = null; textBox1.Text = ("加载图片"); OpenFileDialog file = new OpenFileDialog(); file.InitialDirectory = "."; file.Filter = "所有文件(*.*)|*.*"; file.ShowDialog(); if (file.FileName != string.Empty) { try { pathname = file.FileName; //获得文件的绝对路径 this.pictureBox1.Load(pathname); } catch (Exception ex) { MessageBox.Show(ex.Message); } } string str1 = file.FileName; //str1 = "'" + str1 + "'";//加单引号为符合matlab输入规范 textBox1.Text = (str1); //textBox1.Text = (file.FileName); DiameterCalculation.Class1 c1 = new DiameterCalculation.Class1(); //Object sandNumber; MWArray a1 = c1.linktocsharp(str1); MWNumericArray a2 = (MWNumericArray)a1; textBox2.Text = a2.ToString(); linktocsharpV5.Class1 v5c1 = new linktocsharpV5.Class1(); //MWArray DiameterArray = v3c1.linktocsharpV3(str1); MWArray[] resultlist = new MWArray[2]; resultlist = v5c1.linktocsharpV5(4, str1); //重要!!!m函数有多个返回值时在第一个参数里写入返回值个数,第二个参数才是输入m函数的第一个输入参数 MWNumericArray DiameterArray = (MWNumericArray)resultlist[0]; //返回每一粒沙子的直径数组,为n行1列的二维数组 MWNumericArray SandNumber = (MWNumericArray)resultlist[1]; //沙尘个数 MWNumericArray DiameterNumber = (MWNumericArray)resultlist[2]; //返回以50um为单位的粒径累加结果数组 MWNumericArray xlength = (MWNumericArray)resultlist[3]; //返回以50um为单位的粒径累加结果数组 double[,] DA = new double[(int)SandNumber, 1]; //matlab函数返回值为二维数组,因此需要用二维数组接收 DA = (double[, ])DiameterArray.ToArray(); double[,] DN = new double[(int)xlength, 1]; //matlab函数返回值为二维数组,因此需要用二维数组接收 DN = (double[, ])DiameterNumber.ToArray(); //textBox3.Text = DA[(int)a2 - 1, 0].ToString(); //textBox3.Text = DA[(int)SandNumber - 1, 0].ToString(); chart1.Series.Clear(); ChartHelper.AddSeries(chart1, "由小到大每一粒沙尘的粒径", SeriesChartType.Column, Color.Transparent, Color.Red, true); // ChartHelper.AddSeries(chart1, "由小到大每一粒沙尘的粒径", SeriesChartType.Spline, Color.Red, Color.Red); // ChartHelper.SetTitle(chart1, "由小到大每一粒沙尘的粒径", new Font("微软雅黑", 8), Docking.Top, Color.Black); ChartHelper.SetStyle(chart1, Color.Transparent, Color.Black); ChartHelper.SetLegend(chart1, Docking.Top, StringAlignment.Center, Color.Transparent, Color.Black); ChartHelper.SetXY(chart1, "", "粒径(*50um)", StringAlignment.Far, Color.Black, Color.Black, AxisArrowStyle.SharpTriangle, 0, 0); ChartHelper.SetMajorGrid(chart1, Color.Transparent, 20, 50); List <int> xData = new List <int>() { }; int i, j; for (i = 1; i <= (int)SandNumber; i++) { xData.Add(i); } List <double> yData = new List <double>() { }; for (j = 0; j <= (int)SandNumber - 1; j++) { yData.Add(DA[j, 0]); } chart1.Series[0].Points.DataBindXY(xData, yData); chart2.Series.Clear(); ChartHelper.AddSeries(chart2, "该粒径范围内沙尘个数", SeriesChartType.Column, Color.Lime, Color.Blue, true); // ChartHelper.AddSeries(chart2, "曲线图", SeriesChartType.Spline, Color.Red, Color.Red); // ChartHelper.SetTitle(chart2, "柱状图与曲线图", new Font("微软雅黑", 12), Docking.Bottom, Color.Black); ChartHelper.SetStyle(chart2, Color.Transparent, Color.Black); ChartHelper.SetLegend(chart2, Docking.Top, StringAlignment.Center, Color.Transparent, Color.Black); ChartHelper.SetXY(chart2, "粒径(*50um)", "个数", StringAlignment.Far, Color.Black, Color.Black, AxisArrowStyle.SharpTriangle, 4, (int)(DN[0, 0] / 10)); ChartHelper.SetMajorGrid(chart2, Color.Transparent, 20, 2); List <int> xData2 = new List <int>() { }; int i2, j2; for (i2 = 1; i2 <= (int)xlength; i2++) { xData2.Add(i2); } List <double> yData2 = new List <double>() { }; for (j2 = 0; j2 <= (int)xlength - 1; j2++) { yData2.Add(DN[j2, 0]); } chart2.Series[0].Points.DataBindXY(xData2, yData2); //textBox2.Text = (sandNumber.ToString); string pathname2; pathname2 = "D:\\op\\tempresult.png"; //获得文件的绝对路径 //this.pictureBox2.Load(pathname2);//load貌似过时了? // this.pictureBox2.Image = Image.FromFile(pathname2); // pictureBox2.Image.Dispose(); FileStream pFileStream = new FileStream(pathname2, FileMode.Open, FileAccess.Read); pictureBox2.Image = Image.FromStream(pFileStream); pFileStream.Close(); pFileStream.Dispose(); }