public override void DrawChart(Series nseries, MetaFile ametafile, int posx, int posy, object achart) { System.Windows.Forms.DataVisualization.Charting.Chart nchart = new System.Windows.Forms.DataVisualization.Charting.Chart(); float afontsize = Convert.ToSingle(Math.Round(nseries.FontSize * nseries.Resolution / 100)); //achart.BackColor:=clTeeColor; nchart.BackColor = Color.White; /*achart.LeftAxis.LabelsFont.Name:=nchart.WFontName; * achart.BottomAxis.LabelsFont.Name:=nchart.WFontName; * achart.Legend.Font.Name:=nchart.WFontName; * achart.LeftAxis.LabelsFont.Style:=CLXIntegerToFontStyle(nchart.FontStyle); * achart.BottomAxis.LabelsFont.Style:=CLXIntegerToFontStyle(nchart.FontStyle); * achart.Legend.Font.Size:=aFontSize; * achart.Legend.Font.Style:=CLXIntegerToFontStyle(nchart.FontStyle);*/ /*achart.Legend.Visible:=nchart.ShowLegend;*/ // autorange and other ranges /*achart.LeftAxis.Maximum:=Series.HighValue; * achart.LeftAxis.Minimum:=Series.LowValue; * achart.LeftAxis.Automatic:=false; * achart.LeftAxis.AutomaticMaximum:=Series.AutoRangeH; * achart.LeftAxis.AutomaticMinimum:=Series.AutoRangeL; * achart.LeftAxis.LabelsAngle:=nchart.VertFontRotation mod 360; * achart.LeftAxis.LabelsFont.Size:=Round(nchart.VertFontSize*nchart.Resolution/100); * achart.BottomAxis.LabelsAngle:=nchart.HorzFontRotation mod 360; * achart.BottomAxis.LabelsFont.Size:=Round(nchart.HorzFontSize*nchart.Resolution/100);*/ nchart.ChartAreas.Add(""); if (nseries.Effect3D) { nchart.ChartAreas[0].Area3DStyle.Enable3D = nseries.Effect3D;; nchart.ChartAreas[0].Area3DStyle.IsClustered = true; } //nchart.ChartAreas[0].AxisX.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot; //nchart.ChartAreas[0].AxisY.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot; //nchart.ChartAreas[0].AxisY.MinorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot; //nchart.ChartAreas[0].AxisX.MinorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot; nchart.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot; nchart.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot; if (nseries.Logaritmic) { nchart.ChartAreas[0].AxisY.IsLogarithmic = true; nchart.ChartAreas[0].AxisY.LogarithmBase = nseries.LogBase; } nchart.ChartAreas[0].AxisY.IsReversed = nseries.Inverted; //nchart.ChartAreas[0].AxisX.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount; nchart.ChartAreas[0].AxisX.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.FixedCount; nchart.ChartAreas[0].AxisX.LabelStyle.Interval = 1; if (!nseries.AutoRangeH) { //nchart.ChartAreas[0].AxisX.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode. nchart.ChartAreas[0].AxisY.Maximum = nseries.HighValue; } if (nseries.VertFontRotation != 0) { nchart.ChartAreas[0].AxisY.LabelStyle = new System.Windows.Forms.DataVisualization.Charting.LabelStyle(); nchart.ChartAreas[0].AxisY.LabelStyle.Angle = nseries.VertFontRotation; } if (nseries.HorzFontRotation != 0) { nchart.ChartAreas[0].AxisY.LabelStyle = new System.Windows.Forms.DataVisualization.Charting.LabelStyle(); nchart.ChartAreas[0].AxisY.LabelStyle.Angle = nseries.HorzFontRotation; } if (!nseries.AutoRangeL) { //nchart.ChartAreas[0].AxisX.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode. nchart.ChartAreas[0].AxisY.Minimum = nseries.LowValue; } if (nseries.ShowLegend) { nchart.Legends.Add(""); } // Create series int acolor = 0; int idxserie = 0; foreach (SeriesItem sitem in nseries.SeriesItems) { System.Windows.Forms.DataVisualization.Charting.Series chartserie = nchart.Series.Add(sitem.Caption); switch (sitem.ChartStyle) { case ChartType.Area: chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area; break; case ChartType.Gantt: case ChartType.Arrow: chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; break; case ChartType.Bar: switch (nseries.MultiBar) { case BarType.Stacked: chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn; break; case BarType.Stacked100: chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn100; break; default: chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column; break; } break; case ChartType.Bubble: chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bubble; break; case ChartType.Horzbar: switch (nseries.MultiBar) { case BarType.Stacked: chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedBar; break; case BarType.Stacked100: chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedBar100; break; default: chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bar; break; } break; case ChartType.Line: chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; break; case ChartType.Pie: chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie; break; case ChartType.Point: chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point; break; } chartserie.Label = sitem.Caption; if (nseries.ShowHint) { chartserie.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Square; } else { chartserie.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.None; } if (sitem.ChartStyle == ChartType.Pie) { // Set these other two properties so that you can see the connecting lines nchart.Series[0].BorderWidth = 1; nchart.Series[0].BorderColor = System.Drawing.Color.FromArgb(26, 59, 105); // Set the pie label as well as legend text to be displayed as percentage // The P2 indicates a precision of 2 decimals //nchart.Series[0].Label = "#VALX #PERCENT{P2} #VAL"; nchart.Series[0].Label = "#PERCENT{P2}"; nchart.Series[0]["PieLabelStyle"] = "Outside"; //nchart.Legends[0].CustomItems.Add(npoint.Color, sitem.ValueCaptions[j]); //nchart.Series[0].LegendText = "#VALX (#PERCENT) #VAL"; nchart.Series[0].LegendText = "#VALX #VAL"; //this.Chart2.Series[0].LegendText = "#VALX (#PERCENT)" //nchart.Legends[0].= sitem.ValueCaptions[j]; //n.Legends.Add("Legend1"); nchart.Legends[0].Enabled = true; nchart.Legends[0].Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Bottom; nchart.Legends[0].Alignment = System.Drawing.StringAlignment.Center; } if (sitem.Color > 0) { chartserie.Color = GraphicUtils.ColorFromInteger(sitem.Color); } else { chartserie.Color = GraphicUtils.ColorFromInteger(SeriesColors[acolor]); } double total = 0; if (nseries.MarkStyle == 1) { for (int j = 0; j < sitem.Values.Count; j++) { object nobj = sitem.Values[j]; if (DoubleUtil.IsNumericType(nobj)) { total = total + Convert.ToDouble(nobj); } } } for (int j = 0; j < sitem.Values.Count; j++) { string ncaption = sitem.ValueCaptions[j]; if (ncaption == null) { ncaption = ""; } int idx = chartserie.Points.AddXY(ncaption, sitem.Values[j]); System.Windows.Forms.DataVisualization.Charting.DataPoint npoint = chartserie.Points[idx]; if (sitem.ChartStyle != ChartType.Pie) { if (nseries.ShowHint) { switch (nseries.MarkStyle) { case 1: npoint.Label = ""; if ((DoubleUtil.IsNumericType(sitem.Values[j])) && (total != 0)) { npoint.Label = (Convert.ToDouble(sitem.Values[j]) / total * 100).ToString("N2") + "%"; } break; case 6: npoint.Label = ""; if (DoubleUtil.IsNumericType(sitem.Values[j])) { double nuevo_valor = Convert.ToDouble(sitem.Values[j]); npoint.Label = nuevo_valor.ToString("N1") + "%"; } break; default: npoint.Label = sitem.Values[j].ToString(); break; } } else { npoint.Label = ""; } } if (nseries.SeriesItems.Count < 2) { if (sitem.Colors[j] >= 0) { npoint.Color = GraphicUtils.ColorFromInteger(sitem.Colors[j]); } else { npoint.Color = GraphicUtils.ColorFromInteger(SeriesColors[acolor]); } if ((sitem.ChartStyle == ChartType.Pie) || nseries.ShowLegend) { if (sitem.ChartStyle == ChartType.Pie) { } else { if (j != 0) { nchart.Legends[0].CustomItems.Add(npoint.Color, sitem.ValueCaptions[j]); } else { nchart.Legends.Add(sitem.ValueCaptions[j]); } } acolor = ((acolor + 1) % (MAX_SERIECOLORS)); } } else { if (sitem.Colors[j] >= 0) { npoint.Color = GraphicUtils.ColorFromInteger(sitem.Colors[j]); } else { npoint.Color = GraphicUtils.ColorFromInteger(SeriesColors[acolor]); } } } acolor = ((acolor + 1) % (MAX_SERIECOLORS)); idxserie++; } Bitmap nbitmap = new Bitmap(Convert.ToInt32(Convert.ToSingle(Twips.TwipsToInch(nseries.PrintWidth)) * nseries.Resolution), Convert.ToInt32(Convert.ToSingle(Twips.TwipsToInch(nseries.PrintHeight)) * nseries.Resolution), PixelFormat.Format24bppRgb); Rectangle rec = new Rectangle(0, 0, nbitmap.Width, nbitmap.Height); nchart.SetBounds(0, 0, nbitmap.Width, nbitmap.Height); nchart.Update(); nchart.DrawToBitmap(nbitmap, rec); System.IO.MemoryStream mstream = new MemoryStream(); nbitmap.Save(mstream, ImageFormat.Bmp); MetaObjectImage metaobj = new MetaObjectImage(); metaobj.MetaType = MetaObjectType.Image; metaobj.Top = posy; metaobj.Left = posx; metaobj.Width = nseries.PrintWidth; metaobj.Height = nseries.PrintHeight; metaobj.CopyMode = 20; metaobj.DrawImageStyle = ImageDrawStyleType.Stretch; metaobj.DPIRes = Convert.ToInt32(nseries.Resolution); metaobj.PreviewOnly = false; metaobj.StreamPos = ametafile.Pages[ametafile.CurrentPage].AddStream(mstream, false); metaobj.SharedImage = false; metaobj.StreamSize = mstream.Length; ametafile.Pages[ametafile.CurrentPage].Objects.Add(metaobj); base.DrawChart(nseries, ametafile, posx, posy, achart); }