public Bitmap Show_MSChart() { try { if (!Check_Chart()) return null; ChartArea chartArea = new ChartArea("chartArea"); Grid grid = new Grid(); grid.LineDashStyle = ChartDashStyle.Solid; grid.LineColor = Color.Black; Legend lengend = new Legend(); lengend.Docking = Docking.Right; chartArea.AxisX.MajorGrid = grid; chartArea.AxisY.MajorGrid = grid; chartArea.AxisX.Interval = 1; chartArea.AxisX.IsLabelAutoFit = false; chartArea.BackColor = Color.FromArgb(0xEF, 0xEF, 0xEF); Series series = new Series("危险度"); series.ChartType = SeriesChartType.Column; //series.IsValueShownAsLabel = true; series.Color = dataColor; series.BorderWidth = 0; SmartLabelStyle smartLabelStyle = new SmartLabelStyle(); smartLabelStyle.AllowOutsidePlotArea = LabelOutsidePlotAreaStyle.Yes; series.SmartLabelStyle = smartLabelStyle; series.Points.DataBindXY(dataTable.DefaultView, dataX, dataTable.DefaultView, dataY); Chart chart = new Chart(); chart.Width = width; chart.Height = height; chart.ChartAreas.Add(chartArea); chart.Series.Add(series); chart.Legends.Add(lengend); MemoryStream memoryStream = new MemoryStream(); chart.SaveImage(memoryStream, ChartImageFormat.Jpeg); Bitmap bitmap = new Bitmap(memoryStream); return bitmap; } catch (Exception ex) { return null; } }
private void DisplayMatrix(double[,] Matrix, List<string> ListLabelX, List<string> ListLabelY, bool IsDisplayValues, string TitleForGraph, int SquareSize, bool IsToBeDisplayed, string PathName) { int IdxValue = 0; Series CurrentSeries = new Series("Matrix"); CurrentSeries.ChartType = SeriesChartType.Point; // loop on all the desciptors for (int iDesc = 0; iDesc < ListLabelX.Count; iDesc++) { for (int jDesc = 0; jDesc < ListLabelY.Count; jDesc++) { CurrentSeries.Points.AddXY(iDesc + 1, jDesc + 1); CurrentSeries.Points[IdxValue].MarkerStyle = MarkerStyle.Square; CurrentSeries.Points[IdxValue].MarkerSize = SquareSize; CurrentSeries.Points[IdxValue].BorderColor = Color.Black; CurrentSeries.Points[IdxValue].BorderWidth = 1; double Value = Matrix[iDesc, jDesc]; if (IsDisplayValues) CurrentSeries.Points[IdxValue].Label = string.Format("{0:0.###}", Math.Abs(Value)); CurrentSeries.Points[IdxValue].ToolTip = Math.Abs(Value) + " <=> | " + Matrix[iDesc, jDesc].ToString() + " |"; int ConvertedValue = (int)(Math.Abs(Value) * (CompleteScreening.GlobalInfo.LUT[0].Length - 1)); CurrentSeries.Points[IdxValue++].Color = Color.FromArgb(CompleteScreening.GlobalInfo.LUT[0][ConvertedValue], CompleteScreening.GlobalInfo.LUT[1][ConvertedValue], CompleteScreening.GlobalInfo.LUT[2][ConvertedValue]); } } for (int iDesc = 0; iDesc < ListLabelX.Count * ListLabelX.Count; iDesc++) CurrentSeries.Points[iDesc].AxisLabel = CompleteScreening.ListDescriptors.GetListNameActives()[iDesc / ListLabelX.Count]; SmartLabelStyle SStyle = new SmartLabelStyle(); SimpleForm NewWindow = new SimpleForm(); NewWindow.Height = SquareSize * ListLabelY.Count + 220; NewWindow.Width = SquareSize * ListLabelX.Count + 245; ChartArea CurrentChartArea = new ChartArea("Default"); for (int i = 0; i < CompleteScreening.ListDescriptors.GetListNameActives().Count; i++) { CustomLabel lblY = new CustomLabel(); lblY.ToPosition = i * 2 + 2; lblY.Text = ListLabelY[i]; CurrentChartArea.AxisY.CustomLabels.Add(lblY); } CurrentChartArea.AxisY.LabelAutoFitStyle = LabelAutoFitStyles.LabelsAngleStep30; CurrentChartArea.BorderColor = Color.Black; NewWindow.chartForSimpleForm.ChartAreas.Add(CurrentChartArea); CurrentSeries.SmartLabelStyle.Enabled = true; NewWindow.chartForSimpleForm.TextAntiAliasingQuality = TextAntiAliasingQuality.High; NewWindow.chartForSimpleForm.Series.Add(CurrentSeries); CurrentChartArea.Axes[0].MajorGrid.Enabled = false; CurrentChartArea.Axes[0].Minimum = 0; CurrentChartArea.Axes[0].Maximum = ListLabelX.Count + 1; CurrentChartArea.Axes[1].MajorGrid.Enabled = false; CurrentChartArea.Axes[1].Minimum = 0; CurrentChartArea.Axes[1].Maximum = ListLabelY.Count + 1; CurrentChartArea.AxisX.Interval = 1; CurrentChartArea.AxisY.Interval = 1; Title CurrentTitle = new Title(TitleForGraph); NewWindow.chartForSimpleForm.Titles.Add(CurrentTitle); NewWindow.chartForSimpleForm.Titles[0].Font = new Font("Arial", 9); if (IsToBeDisplayed) NewWindow.Show(); else NewWindow.chartForSimpleForm.SaveImage(PathName + "_Matrix.emf", ChartImageFormat.Emf); NewWindow.Text = TitleForGraph; NewWindow.chartForSimpleForm.Update(); NewWindow.chartForSimpleForm.Show(); NewWindow.Controls.AddRange(new System.Windows.Forms.Control[] { NewWindow.chartForSimpleForm }); }
private Chart GenerateGraph() { Chart ChartToBeReturned = new Chart(); int IdxValue = 0; if (IsAutomatedMinMax) { Max = this.Input.Max(); Min = this.Input.Min(); } CurrentSeries = new Series(); CurrentSeries.ChartType = SeriesChartType.Point; // loop on all the desciptors for (int idxCol = 0; idxCol < Input.Count; idxCol++) { for (int idxRow = 0; idxRow < Input[idxCol].Count; idxRow++) { CurrentSeries.Points.AddXY(idxCol + 1, idxRow + 1); CurrentSeries.Points[IdxValue].MarkerStyle = Marker_Style; CurrentSeries.Points[IdxValue].MarkerSize = SquareSize; CurrentSeries.Points[IdxValue].BorderColor = Color.Black; CurrentSeries.Points[IdxValue].BorderWidth = 1; if (Input[idxCol].ListTags != null) CurrentSeries.Points[IdxValue].Tag = Input[idxCol].ListTags[idxRow]; double Value = this.Input[idxCol][idxRow]; if (this.IsDisplayValues) CurrentSeries.Points[IdxValue].Label = Value.ToString("N" + DigitNumber);// string.Format("{0:0.###}", Math.Abs(Value)); else CurrentSeries.Points[IdxValue].Label = ""; string TmpToolTip = this.Input[idxCol].Name ; if (idxRow < this.Input.ListRowNames.Count) { TmpToolTip += "\n vs.\n" + this.Input.ListRowNames[idxRow] + "\n\n" + Value.ToString("N" + DigitNumber); } CurrentSeries.Points[IdxValue].ToolTip = TmpToolTip; if ((Max != Min) && (double.IsNaN(Value) == false) && (Value != -1)) { int ConvertedValue = (int)((Value - Min) / (Max - Min) * (CurrentLUT[0].Length - 1)); CurrentSeries.Points[IdxValue].Color = Color.FromArgb(CurrentLUT[0][ConvertedValue], CurrentLUT[1][ConvertedValue], CurrentLUT[2][ConvertedValue]); if (this.IsDisplayValues) { CurrentSeries.Points[IdxValue].LabelFormat = "N" + DigitNumber; CurrentSeries.Points[IdxValue].IsValueShownAsLabel = true; CurrentSeries.Points[IdxValue].Font = new Font("Arial", 8); } } else CurrentSeries.Points[IdxValue].Color = Color.Transparent; CurrentSeries.Points[IdxValue++].AxisLabel = this.Input[idxCol].Name; } } SmartLabelStyle SStyle = new SmartLabelStyle(); ChartArea CurrentChartArea = new ChartArea("Default"); for (int i = 0; i < this.Input.ListRowNames.Count; i++) { CustomLabel lblY = new CustomLabel(); lblY.ToPosition = i * 2 + 2; lblY.Text = this.Input.ListRowNames[i]; CurrentChartArea.AxisY.CustomLabels.Add(lblY); } CurrentChartArea.AxisY.LabelAutoFitStyle = LabelAutoFitStyles.LabelsAngleStep30; CurrentChartArea.BorderColor = Color.Black; ChartToBeReturned.ChartAreas.Add(CurrentChartArea); CurrentSeries.SmartLabelStyle.Enabled = true; ChartToBeReturned.TextAntiAliasingQuality = TextAntiAliasingQuality.High; ChartToBeReturned.Series.Add(CurrentSeries); CurrentChartArea.Axes[0].MajorGrid.Enabled = false; CurrentChartArea.Axes[0].Minimum = 0; CurrentChartArea.Axes[0].Maximum = this.Input.Count + 1; CurrentChartArea.Axes[1].MajorGrid.Enabled = false; CurrentChartArea.Axes[1].Minimum = 0; CurrentChartArea.Axes[1].Maximum = this.Input.ListRowNames.Count + 1; CurrentChartArea.AxisX.Interval = 1; CurrentChartArea.AxisY.Interval = 1; Title CurrentTitle = new Title(this.Input.Name); ChartToBeReturned.Titles.Add(CurrentTitle); ChartToBeReturned.Titles[0].Font = new Font("Arial", 9); ChartToBeReturned.Anchor = (System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right); if ((IsWellClassLegend) || (IsCellularPhenotypeLegend)) { Legend MyLegend = new Legend(); ChartToBeReturned.Legends.Add(MyLegend); ChartToBeReturned.Legends[0].ShadowOffset = 5; ChartToBeReturned.CustomizeLegend += new EventHandler<CustomizeLegendEventArgs>(ChartToBeReturned_CustomizeLegend); } return ChartToBeReturned; }