Example #1
0
        /// <summary>
        /// 确定Chart的宽度值,以磅为单位
        /// </summary>
        /// <param name="DrawingChart">进行绘图的Chart</param>
        /// <param name="PointsCount">选择的基坑区域的数量</param>
        /// <param name="LeastWidth_Chart">Chart对象的宽度的最小值,即使图表中只有很少的点</param>
        /// <param name="LeastWidth_Column">柱形图中每一个柱形的最小宽度,用来进行基本的文本书写</param>
        /// <returns></returns>
        /// <remarks></remarks>
        private double GetChartWidth(Microsoft.Office.Interop.Excel.Chart DrawingChart, UInt16 PointsCount, double
                                     LeastWidth_Chart, double LeastWidth_Column, double Margin, ref
                                     double InsideWidth)
        {
            double ChartWidth = LeastWidth_Chart;

            InsideWidth = LeastWidth_Chart - Margin;
            //
            Microsoft.Office.Interop.Excel.Chart            with_1 = DrawingChart;
            Microsoft.Office.Interop.Excel.SeriesCollection src    = with_1.SeriesCollection();
            UInt16     n        = src.Count;
            double     hh       = LeastWidth_Chart / PointsCount;
            ChartGroup ChtGroup = with_1.ChartGroups(1);
            // ------------------------------------------------------------------------------------------------
            //1、在已知最小的chart宽度(即最小的PlotArea.InsideWidth)的情况下,验算柱形的宽度是否比指定的最小柱形宽度要大
            double H = InsideWidth;

            // Dim O As Single = ChtGroup.Overlap / 100
            ChtGroup.Overlap = 0;
            float  G           = (float)((double)ChtGroup.GapWidth / 100);
            double ColumnWidth = hh / (1 + G + n);

            if (ColumnWidth < LeastWidth_Column)
            {
                // ------------------------------------------------------------------------------------------------
                //2、在已知柱体的最小宽度的情况下,去推算整个PlotArea.InsideWidth的值
            }
            return(ChartWidth);
        }
Example #2
0
 private void CreateChart()
 {
     chart = oWS.ChartObjects().Add(0,0,800,500).Chart;
     chart.SetSourceData(oWS.UsedRange);
     chart.ChartType = Excel.XlChartType.xlColumnClustered;
     chart.ChartStyle = 17;
     foreach (Excel.ChartGroup group in chart.ChartGroups())
     {
         group.GapWidth = 0;
         group.Overlap = 0;
     }
 }