コード例 #1
0
        private void DrawSeries(Grid chartGrid, Canvas chartCanvas, IEnumerable <ISeries> seriesCollection,
                                LegendAddResult legendAddResult, IChartLegend legend)
        {
            //第七步 绘各Series
            this.DrawSeries(chartCanvas, seriesCollection);

            //填充legend
            if (legendAddResult != null &&
                legendAddResult.HasLegend &&
                legend != null)
            {
                this.UpdateLegend(legend, seriesCollection);
            }
        }
コード例 #2
0
        private void FreezeYLayout(ChartCollection <AxisAbs> axisCollection, IChartLegend legend, Canvas chartCanvas, Grid chartGrid, ScrollViewer scrollViewer, Grid chartContentGrid, LegendAddResult legendAddResult, AxisXHeightInfo axisXHeightInfo, AxisYWidthInfo axisYWidthInfo)
        {
            //添加scrollViewer
            scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
            scrollViewer.VerticalScrollBarVisibility   = ScrollBarVisibility.Disabled;
            scrollViewer.Content             = chartContentGrid;
            scrollViewer.VerticalAlignment   = System.Windows.VerticalAlignment.Top;
            scrollViewer.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            chartGrid.Children.Add(scrollViewer);


            //左中右三列布局,legend另算
            var chartGridRowColumnDefinition = new ChartGridRowColumnDefinition(legendAddResult.HasLegend, legend, chartGrid, axisYWidthInfo);

            if (legendAddResult.HasLegend)
            {
                this.SetRowColumn(chartGrid, legend.LegendControl, chartGridRowColumnDefinition.Legend);
            }

            if (axisCollection != null && axisCollection.Count > ChartConstant.ZERO_I)
            {
                RowColumnDefinitionItem rowColumnDefinition;
                foreach (var axis in axisCollection)
                {
                    if (axis.AxisType != AxisType.Y)
                    {
                        continue;
                    }

                    switch (axis.DockOrientation)
                    {
                    case ChartDockOrientation.Left:
                        rowColumnDefinition = chartGridRowColumnDefinition.LeftAxis;
                        break;

                    case ChartDockOrientation.Right:
                        rowColumnDefinition = chartGridRowColumnDefinition.RightAxis;
                        break;

                    case ChartDockOrientation.Top:
                    case ChartDockOrientation.Bottom:
                    default:
                        throw new NotImplementedException(axis.DockOrientation.ToString());
                    }

                    this.SetRowColumn(chartGrid, axis.AxisControl, rowColumnDefinition);
                }
            }

            this.SetRowColumn(chartGrid, scrollViewer, chartGridRowColumnDefinition.Chart);



            //上中下三行布局
            var chartGridRowColumnDefinition2 = new ChartGridRowColumnDefinition(chartContentGrid, axisXHeightInfo);

            if (axisCollection != null && axisCollection.Count > ChartConstant.ZERO_I)
            {
                RowColumnDefinitionItem rowColumnDefinition;
                foreach (var axis in axisCollection)
                {
                    if (axis.AxisType != AxisType.X)
                    {
                        continue;
                    }

                    switch (axis.DockOrientation)
                    {
                    case ChartDockOrientation.Top:
                        rowColumnDefinition = chartGridRowColumnDefinition2.TopAxis;
                        break;

                    case ChartDockOrientation.Bottom:
                        rowColumnDefinition = chartGridRowColumnDefinition2.BottomAxis;
                        break;

                    case ChartDockOrientation.Left:
                    case ChartDockOrientation.Right:
                    default:
                        throw new NotImplementedException(axis.DockOrientation.ToString());
                    }

                    this.SetRowColumn(chartContentGrid, axis.AxisControl, rowColumnDefinition);
                }
            }
            this.SetRowColumn(chartContentGrid, chartCanvas, chartGridRowColumnDefinition2.Chart);
        }
コード例 #3
0
        private void UpdateFreezeY(AxisFreezeInfo axisFreezeInfo, ChartCollection <AxisAbs> axisCollection, ChartCollection <ISeries> seriesCollection,
                                   IChartLegend legend, Canvas chartCanvas, Grid chartGrid, ScrollViewer scrollViewer, Grid chartContentGrid)
        {
            /************************************************************************************************************
            * 步骤:
            * 1.添加legend,并计算出发四周所占高度或宽度
            * 2.计算X轴总高度
            * 3.根据X轴总高度计算图表区域高度高度(等于Y轴高度)
            * 4.根据Y轴高度绘制Y轴,并计算Y轴宽度
            * 5.根据宽度绘制X轴
            * 6.绘制坐标背景标记线
            * 7.布局UI
            * 8.绘各Series和填充legend
            ************************************************************************************************************/

            //chartGrid.ShowGridLines = true;
            //chartCanvas.Background = ColorBrushHelper.GetNextColor();
            this.Content = chartGrid;


            //第一步 添加legend,并计算出发四周所占高度或宽度
            LegendAddResult legendAddResult = this.AddLegend(legend, chartGrid);

            //第二步 计算X轴总高度
            AxisXHeightInfo axisXHeightInfo = this.CalculateAxisXHeight(axisCollection);

            //第三步 根据X轴总高度计算图表区域高度高度(等于Y轴高度)
            double yAxisHeight = axisFreezeInfo.Height - axisXHeightInfo.TopAxisTotalHeight - axisXHeightInfo.BottomAxisTotalHeight - legendAddResult.Top - legendAddResult.Bottom - this._scrollBarWidth;

            if (yAxisHeight < ChartConstant.ZERO_D)
            {
                yAxisHeight = ChartConstant.ZERO_D;
            }

            //第四步 根据Y轴高度绘制Y轴,并计算Y轴宽度
            AxisYWidthInfo axisYWidthInfo = this.DrawAxisYByAxisXHeightInfo(axisCollection, chartGrid.Children, seriesCollection, yAxisHeight, axisXHeightInfo.TopAxisTotalHeight);


            //第五步 根据宽度绘制X轴
            double width      = this.ActualWidth - axisYWidthInfo.LeftAxisTotalWidth - axisYWidthInfo.RightAxisTotalWidth - legendAddResult.Left - legendAddResult.Right;
            double xAxisWidth = axisFreezeInfo.Width;

            if (xAxisWidth < ChartConstant.ZERO_D)
            {
                xAxisWidth = ChartConstant.ZERO_D;
            }
            else if (xAxisWidth - width < ChartConstant.ZERO_D)
            {
                //真实宽度大于最小值,取更大值
                xAxisWidth = width;
            }
            Dictionary <AxisAbs, List <double> > axisXLabelDic = this.DrawAxisX(axisCollection, seriesCollection, chartContentGrid, xAxisWidth, ChartConstant.ZERO_D);

            chartCanvas.Width  = xAxisWidth;
            chartCanvas.Height = yAxisHeight;
            chartContentGrid.Children.Add(chartCanvas);

            //第六步 绘制坐标背景标记线
            this.DrawAxisBackgroundLabelLine(chartCanvas, axisYWidthInfo.AxisYLabelDic, axisXLabelDic);

            //第七步 布局UI
            this.FreezeYLayout(axisCollection, legend, chartCanvas, chartGrid, scrollViewer, chartContentGrid, legendAddResult, axisXHeightInfo, axisYWidthInfo);

            //第八步 绘各Series和填充legend
            this.DrawSeries(chartGrid, chartCanvas, seriesCollection, legendAddResult, legend);
        }
コード例 #4
0
 public DrawSeriesPara(Grid chartGrid, Canvas chartCanvas, IEnumerable <ISeries> seriesCollection, LegendAddResult legendAddResult, IChartLegend legend)
 {
     this.ChartGrid        = chartGrid;
     this.ChartCanvas      = chartCanvas;
     this.SeriesCollection = seriesCollection;
     this.LegendAddResult  = legendAddResult;
     this.Legend           = legend;
 }
コード例 #5
0
        private void UpdateFreezeX(AxisFreezeInfo axisFreezeInfo, ChartCollection <AxisAbs> axisCollection, ChartCollection <ISeries> seriesCollection,
                                   IChartLegend legend, Canvas chartCanvas, Grid chartGrid, ScrollViewer scrollViewer, Grid chartContentGrid)
        {
            /************************************************************************************************************
            * 步骤:
            * 1.添加legend,并计算出发四周所占高度或宽度
            * 2.计算X轴总高度
            * 3.根据Y轴高度绘制Y轴,并计算Y轴宽度
            * 4.根据Y轴宽度计算X轴宽度并绘制X轴
            * 5.绘制坐标背景标记线
            * 6.绘各Series
            * 7.绘各Series和填充legend
            ************************************************************************************************************/

            this.Content = chartGrid;

            //第一步 添加legend,并计算出发四周所占高度或宽度
            LegendAddResult legendAddResult = this.AddLegend(legend, chartGrid);

            //第二步 计算X轴总高度
            AxisXHeightInfo axisXHeightInfo = this.CalculateAxisXHeight(axisCollection);


            double height = this.ActualHeight - axisXHeightInfo.TopAxisTotalHeight - axisXHeightInfo.BottomAxisTotalHeight - legendAddResult.Top - legendAddResult.Bottom;

            //第三步 根据Y轴高度绘制Y轴,并计算Y轴宽度
            double yAxisHeight = axisFreezeInfo.Height;

            if (yAxisHeight < ChartConstant.ZERO_D)
            {
                yAxisHeight = ChartConstant.ZERO_D;
            }
            else if (yAxisHeight - height < ChartConstant.ZERO_D)
            {
                //真实高度大于最小值,取更大值
                yAxisHeight = height;
            }
            AxisYWidthInfo axisYWidthInfo = this.DrawAxisYByAxisXHeightInfo(axisCollection, chartContentGrid.Children, seriesCollection, yAxisHeight, ChartConstant.ZERO_D);


            //第四步 根据Y轴宽度计算X轴宽度并绘制X轴
            double xAxisWidth = axisFreezeInfo.Width - axisYWidthInfo.LeftAxisTotalWidth - axisYWidthInfo.RightAxisTotalWidth - legendAddResult.Left - legendAddResult.Right - this._scrollBarWidth;

            if (xAxisWidth < ChartConstant.ZERO_D)
            {
                xAxisWidth = ChartConstant.ZERO_D;
            }
            Dictionary <AxisAbs, List <double> > axisXLabelDic = this.DrawAxisX(axisCollection, seriesCollection, chartGrid, xAxisWidth, axisYWidthInfo.LeftAxisTotalWidth);


            chartCanvas.Width  = xAxisWidth;
            chartCanvas.Height = yAxisHeight;
            chartContentGrid.Children.Add(chartCanvas);

            //第五步 绘制坐标背景标记线
            this.DrawAxisBackgroundLabelLine(chartCanvas, axisYWidthInfo.AxisYLabelDic, axisXLabelDic);

            //第六步 布局UI
            this.FreezeXLayout(axisCollection, legend, chartCanvas, chartGrid, scrollViewer, chartContentGrid, legendAddResult, axisXHeightInfo, axisYWidthInfo);

            //第七步 绘各Series和填充legend
            this.DrawSeries(chartGrid, chartCanvas, seriesCollection, legendAddResult, legend);
        }
コード例 #6
0
        private void NoneFreezeLayout(ChartCollection <AxisAbs> axisCollection, IChartLegend legend, Canvas chartCanvas, Grid chartGrid, ScrollViewer scrollViewer, LegendAddResult legendAddResult, AxisXHeightInfo axisXHeightInfo, AxisYWidthInfo axisYWidthInfo)
        {
            var chartGridRowColumnDefinition = new ChartGridRowColumnDefinition(legendAddResult.HasLegend, legend, chartGrid, axisYWidthInfo, axisXHeightInfo);

            if (legendAddResult.HasLegend)
            {
                this.SetRowColumn(chartGrid, legend.LegendControl, chartGridRowColumnDefinition.Legend);
            }

            if (axisCollection != null && axisCollection.Count > ChartConstant.ZERO_I)
            {
                RowColumnDefinitionItem rowColumnDefinition;
                foreach (var axis in axisCollection)
                {
                    switch (axis.DockOrientation)
                    {
                    case ChartDockOrientation.Left:
                        rowColumnDefinition = chartGridRowColumnDefinition.LeftAxis;
                        break;

                    case ChartDockOrientation.Top:
                        rowColumnDefinition = chartGridRowColumnDefinition.TopAxis;
                        break;

                    case ChartDockOrientation.Right:
                        rowColumnDefinition = chartGridRowColumnDefinition.RightAxis;
                        break;

                    case ChartDockOrientation.Bottom:
                        rowColumnDefinition = chartGridRowColumnDefinition.BottomAxis;
                        break;

                    default:
                        throw new NotImplementedException(axis.DockOrientation.ToString());
                    }

                    this.SetRowColumn(chartGrid, axis.AxisControl, rowColumnDefinition);
                }
            }

            this.SetRowColumn(chartGrid, scrollViewer, chartGridRowColumnDefinition.Chart);


            chartCanvas.MouseWheel          += ChartCanvas_MouseWheel;
            chartCanvas.MouseLeftButtonDown += ChartCanvas_MouseLeftButtonDown;
            chartCanvas.MouseMove           += ChartCanvas_MouseMove;
        }
コード例 #7
0
        private void UpdateNoneFreeze(AxisFreezeInfo axisFreezeInfo, ChartCollection <AxisAbs> axisCollection, ChartCollection <ISeries> seriesCollection,
                                      IChartLegend legend, Canvas chartCanvas, Grid chartGrid, ScrollViewer scrollViewer)
        {
            /************************************************************************************************************
            * 步骤:
            * 1.添加legend,并计算出发四周所占高度或宽度
            * 2.计算X轴总高度
            * 3.根据X轴总高度计算图表区域高度高度(等于Y轴高度)
            * 4.根据Y轴高度绘制Y轴,并计算Y轴宽度
            * 5.根据Y轴宽度计算X轴宽度并绘制X轴
            * 6.绘制坐标背景标记线
            * 7.布局UI
            * 8.绘各Series和填充legend
            ************************************************************************************************************/

            //chartGrid.ShowGridLines = true;
            //chartCanvas.Background = ColorBrushHelper.GetNextColor();
            this.Content = chartGrid;



            //第一步 添加legend,并计算出发四周所占高度或宽度
            LegendAddResult legendAddResult = this.AddLegend(legend, chartGrid);


            //第二步 计算X轴总高度
            AxisXHeightInfo axisXHeightInfo = this.CalculateAxisXHeight(axisCollection);


            //第三步 根据X轴总高度计算图表区域高度高度(等于Y轴高度)
            double yAxisHeight = axisFreezeInfo.Height - axisXHeightInfo.TopAxisTotalHeight - axisXHeightInfo.BottomAxisTotalHeight - legendAddResult.Top - legendAddResult.Bottom;

            if (yAxisHeight < ChartConstant.ZERO_D)
            {
                yAxisHeight = ChartConstant.ZERO_D;
            }

            //第四步 根据Y轴高度绘制Y轴,并计算Y轴宽度
            AxisYWidthInfo axisYWidthInfo = this.DrawAxisYByAxisXHeightInfo(axisCollection, chartGrid.Children, seriesCollection, yAxisHeight, ChartConstant.ZERO_D);


            //第五步 根据Y轴宽度计算X轴宽度并绘制X轴
            double xAxisWidth = axisFreezeInfo.Width - axisYWidthInfo.LeftAxisTotalWidth - axisYWidthInfo.RightAxisTotalWidth - legendAddResult.Left - legendAddResult.Right;

            if (xAxisWidth < ChartConstant.ZERO_D)
            {
                xAxisWidth = ChartConstant.ZERO_D;
            }
            Dictionary <AxisAbs, List <double> > axisXLabelDic = this.DrawAxisX(axisCollection, seriesCollection, chartGrid, xAxisWidth, ChartConstant.ZERO_D);

            chartCanvas.Width            = xAxisWidth;
            chartCanvas.Height           = yAxisHeight;
            scrollViewer.BorderThickness = new Thickness(ChartConstant.ZERO_D);
            scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
            scrollViewer.VerticalScrollBarVisibility   = ScrollBarVisibility.Hidden;
            scrollViewer.Background = Brushes.Transparent;
            scrollViewer.Content    = chartCanvas;
            chartGrid.Children.Add(scrollViewer);

            //第六步 绘制坐标背景标记线
            this.DrawAxisBackgroundLabelLine(chartCanvas, axisYWidthInfo.AxisYLabelDic, axisXLabelDic);

            //第七步 布局UI
            this.NoneFreezeLayout(axisCollection, legend, chartCanvas, chartGrid, scrollViewer, legendAddResult, axisXHeightInfo, axisYWidthInfo);

            //第八步 绘各Series和填充legend
            this.DrawSeries(chartGrid, chartCanvas, seriesCollection, legendAddResult, legend);
        }