예제 #1
0
        /// <summary>
        /// 直角坐标样式布局
        /// </summary>
        /// <param name="g"></param>
        /// <param name="dcs"></param>
        /// <param name="xa"></param>
        /// <param name="ya"></param>
        /// <param name="y2a"></param>
        /// <param name="gd"></param>
        /// <param name="lb"></param>
        /// <param name="tl"></param>
        /// <param name="lg"></param>
        internal void AddChartStyleSquare(Graphics g, Title tl, XYLabel lb, Grid gd, XAxis xa, YAxis ya, Y2Axis y2a, Legend lg, List <DataCollection> dcs)
        {
            try
            {
                //设置直角坐标绘图区位置、大小(受元素之间的相互影响)
                SetPlotArea(g, tl, lb, xa, ya, y2a, gd, lg, dcs);
                //再次确定大小的原因:根据plot宽度->确定文本角度->重新确定plot高度
                AxisFit.SetTickAngle(g, this, lb, xa);
                SetPlotArea(g, tl, lb, xa, ya, y2a, gd, lg, dcs);

                //ChartArea和PlotArea底色绘制(通用)
                FillColorInChartAreas(g);
                //绘制标题(通用)
                AddTitle(g, tl);
                //直角坐标通用网格线
                AddGirdSquare(g, gd, xa, ya);

                //绘制轴标签(受图例影响)
                AddLabels(g, tl, lb, y2a, lg, dcs);
                //绘制坐标轴刻度线和标记(受数据影响)
                AddTicks(g, lb, xa, ya, y2a);
            }
            catch { }
        }
예제 #2
0
파일: Chart2D.cs 프로젝트: DtSuya/Charts
        public Bitmap AddChart()
        {
            Bitmap bmp = new Bitmap(chartSize.Width, chartSize.Height);
            //绘图质量控制
            Graphics g = Graphics.FromImage(bmp);

            g.SmoothingMode     = SmoothingMode.HighQuality;//抗锯齿
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            //g.CompositingMode = CompositingMode.SourceCopy;
            //g.CompositingQuality = CompositingQuality.HighQuality;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; //文本抗锯齿ClearTypeGridFit/AntiAliasGridFit

            bool isSquare = true;

            //图表组合判断
            if (CombineJudge(ref isSquare))
            {
                //是否含次坐标轴数据
                bool isY2 = false;
                foreach (DataCollection dc in dclist)
                {
                    foreach (DataSeries ds in dc.DataSeriesList)
                    {
                        if (ds.IsY2Data)
                        {
                            isY2 = true;
                            break;
                        }
                    }
                    if (isY2)
                    {
                        break;
                    }
                }
                y2a.IsY2Axis = isY2;

                //坐标轴检查,返回自适应是否开启,待完善
                isAxesfit = AxisFit.AxesFitCheck(dclist, xa, ya, y2a, ra);

                //基础要素布局
                if (isSquare)
                {
                    //cs.AddChartStyle(g, xa, ya, y2a, gd, lb, tl);
                    cs.AddChartStyleSquare(g, tl, lb, gd, xa, ya, y2a, lg, dclist);
                }
                else
                {
                    //极坐标图
                    //额外处理:绘图区PlotArea颜色调整,与总体Area内部颜色一致
                    cs.PlotAreaColor.Border = cs.PlotAreaColor.Fill = cs.ChartAreaColor.Fill;
                    cs.AddChartStylePolar(g, tl, gd, ra, lg, dclist);
                }

                //数据排序绘制
                CombineOrder();
                foreach (DataCollection dc in dclist)
                {
                    if (dc.ChartType == Chart2DTypeEnum.LineChart)
                    {
                        LineCharts.AddLines(dc, g, cs, xa, ya, y2a);
                    }
                    else if (dc.ChartType == Chart2DTypeEnum.AreaChart)
                    {
                        AreaCharts.AddAreas((DataCollectionArea)dc, g, cs, xa, ya, y2a);
                    }
                    else if (dc.ChartType == Chart2DTypeEnum.BarChart)
                    {
                        BarCharts.AddBars((DataCollectionBar)dc, g, cs, xa, ya, y2a);
                    }
                    else if (dc.ChartType == Chart2DTypeEnum.PieChart)
                    {
                        PieCharts.AddPie((DataCollectionPie)dc, g, cs);
                    }
                    else if (dc.ChartType == Chart2DTypeEnum.PolorChart)
                    {
                        PolarCharts.AddPolar((DataCollectionPolar)dc, g, cs, ra);
                        cs.AddRosebarTick(g, ra);
                    }
                }
                if (lg.IsLegendVisible)
                {
                    lg.AddLegend(g, dclist, cs, tl);
                }
            }
            else
            {
                //默认空白直角坐标底图
                cs.AddChartStyle(g, tl, lb, gd, xa, ya, y2a);
            }


            ////AxisFit.ConvertValueToPoint_Tick(dc, "yyyyMMdd HH:mm", xa, ya, y2a);

            ////cs.AddChartStyle(g, dc, ca, xa, ya, y2a, gd, lb, tl, lg);
            ////if (dc_sub.DataSeriesList.Count > 0)
            ////    AddSubs(g, cs, dc_sub, xa, ya, y2a);


            g.Dispose();
            GC.Collect();
            return(bmp);
        }