예제 #1
0
        private void InitAnnotation()
        {
            Bitmap legendBitmap = new Bitmap(100, 50);

            using (ChartControl fakeChart = (ChartControl)chartControl1.Clone()) {
                fakeChart.Legend.Visible        = true;
                fakeChart.BorderOptions.Visible = false;
                fakeChart.Padding.All           = 0;

                fakeChart.Legend.Border.Visible      = false;
                fakeChart.Legend.Margins.All         = 0;
                fakeChart.Legend.Padding.All         = 0;
                fakeChart.Legend.BackColor           = Color.Transparent;
                fakeChart.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.LeftOutside;
                fakeChart.Legend.AlignmentVertical   = LegendAlignmentVertical.TopOutside;

                ((XYDiagram)fakeChart.Diagram).DefaultPane.Visible = false;


                fakeChart.DrawToBitmap(legendBitmap, new Rectangle(Point.Empty, legendBitmap.Size));
            }
            chartControl1.Annotations.Clear();
            chartControl1.Annotations.AddImageAnnotation("Legend", legendBitmap);
            chartControl1.Annotations[0].RuntimeMoving    = true;
            chartControl1.Annotations[0].Border.Thickness = 2;
            chartControl1.Annotations[0].Border.Color     = Color.Gray;
            chartControl1.Annotations[0].ConnectorStyle   = AnnotationConnectorStyle.None;
        }
 private void layoutView1_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e)
 {
     if (e.Column == colProducts)
     {
         if (e.IsGetData)
         {
             int    personId = (int)dataSet.Tables["Persons"].Rows[e.ListSourceRowIndex]["ID"];
             Bitmap img      = null;
             if (unboundData.ContainsKey(personId))
             {
                 img = unboundData[personId];
             }
             else
             {
                 DataView dataView = dataSet.Tables["Products"].DefaultView;
                 dataView.RowFilter = string.Format("ID = {0}", personId);
                 foreach (Series s in chart.Series)
                 {
                     s.DataSource = dataView;
                 }
                 chart.RefreshData();
                 LayoutView     view      = (LayoutView)sender;
                 LayoutViewInfo viewInfo  = (LayoutViewInfo)view.GetViewInfo();
                 Size           chartSize = Size.Empty;
                 foreach (LayoutViewField field in view.TemplateCard.Items)
                 {
                     if (field.FieldName == "colProducts")
                     {
                         chartSize = field.Size;
                         break;
                     }
                 }
                 chart.Size = chartSize;
                 img        = new Bitmap(chartSize.Width, chartSize.Height);
                 chart.DrawToBitmap(img, new Rectangle(Point.Empty, chartSize));
                 unboundData.Add(personId, img);
             }
             e.Value = img;
         }
     }
 }
예제 #3
0
        Bitmap GetMarkerImage(ChartControl chart, Series series)
        {
            Bitmap bitmap        = null;
            Series currentSeries = null;

            foreach (Series fakeSeries in chart.Series)
            {
                if (fakeSeries.Name == series.Name)
                {
                    currentSeries           = fakeSeries;
                    fakeSeries.ShowInLegend = true;
                }
                else
                {
                    fakeSeries.ShowInLegend = false;
                }
            }
            if (currentSeries != null)
            {
                XYDiagram2D diagram = chart.Diagram as XYDiagram2D;
                if (diagram != null)
                {
                    diagram.DefaultPane.Visible = false;
                }
                SeriesViewColorEachSupportBase colorEachView = currentSeries.View as SeriesViewColorEachSupportBase;
                if (colorEachView != null && colorEachView.ColorEach)
                {
                    chart.Size = new Size(chart.Legend.MarkerSize.Width, chart.Legend.MarkerSize.Height * currentSeries.Points.Count);
                }
                else
                {
                    chart.Size = chart.Legend.MarkerSize;
                }
                bitmap = new Bitmap(chart.Size.Width, chart.Size.Height);
                chart.DrawToBitmap(bitmap, new Rectangle(Point.Empty, bitmap.Size));
            }
            return(bitmap);
        }