示例#1
0
        private void UpdateAll()
        {
            if (this.IgnoreUpdateChart())
            {
                return;
            }

            AxisFreezeInfo            axisFreezeInfo = this.GetAxisFreezeInfo();
            ChartCollection <AxisAbs> axes           = this.Axes;
            ChartCollection <ISeries> series         = this.Series;
            IChartLegend legend           = this.Legend;
            Grid         chartGrid        = this._chartGrid;
            Canvas       chartCanvas      = this._chartCanvas;
            Grid         chartContentGrid = this._chartContentGrid;
            ScrollViewer scrollViewer     = this._scrollViewer;

            this.Content               = null;
            scrollViewer.Content       = null;
            this._scrollViewer.Content = null;
            chartGrid.Children.Clear();
            chartCanvas.Children.Clear();
            chartCanvas.MouseWheel          -= ChartCanvas_MouseWheel;
            chartCanvas.MouseLeftButtonDown -= ChartCanvas_MouseLeftButtonDown;
            chartCanvas.MouseMove           -= ChartCanvas_MouseMove;
            chartGrid.RowDefinitions.Clear();
            chartGrid.ColumnDefinitions.Clear();
            chartContentGrid.Children.Clear();
            chartContentGrid.RowDefinitions.Clear();
            chartContentGrid.ColumnDefinitions.Clear();

            switch (axisFreezeInfo.AxisFreezeType)
            {
            case AxisFreezeType.None:
                this.UpdateNoneFreeze(axisFreezeInfo, axes, series, legend, chartCanvas, chartGrid, scrollViewer);
                break;

            case AxisFreezeType.X:
                this.UpdateFreezeX(axisFreezeInfo, axes, series, legend, chartCanvas, chartGrid, scrollViewer, chartContentGrid);
                break;

            case AxisFreezeType.Y:
                this.UpdateFreezeY(axisFreezeInfo, axes, series, legend, chartCanvas, chartGrid, scrollViewer, chartContentGrid);
                break;

            case AxisFreezeType.All:
                this.UpdateFreezeAll(axisFreezeInfo, axes, series, legend, chartCanvas, chartGrid, scrollViewer, chartContentGrid);
                break;

            default:
                throw new NotImplementedException(axisFreezeInfo.AxisFreezeType.ToString());
            }
        }
示例#2
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);
        }
示例#3
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);
        }
示例#4
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);
        }