Пример #1
0
 private BurndownChartWizard(IChartSpace chartSpace, BurndownChartData data, CartesianAxes axes, IBarChart barChart, ILineChart lineChart)
 {
     this.chartSpace = chartSpace;
     this.data       = data;
     this.axes       = axes;
     this.barChart   = barChart;
     this.lineChart  = lineChart;
 }
Пример #2
0
        public static BurndownChartWizard BuildBurndownChart(IChartSpace chartSpace, BurndownChartData data)
        {
            using (ISpreadsheetDocument spreadsheet = chartSpace.OpenSpreadsheetDocument())
            {
                IWorksheet seriesSheet    = spreadsheet.Workbook.AppendWorksheet("Series");
                IWorksheet connectorSheet = spreadsheet.Workbook.AppendWorksheet("Connector");

                double total = data.Categories.Sum(c => c.Series.Sum(s => s.Value));

                seriesSheet.Cells[0, 1].SetValue("Offset");
                seriesSheet.Cells[0, 2].SetValue("Total");

                seriesSheet.Cells[1, 0].SetValue("Total");
                connectorSheet.Cells[1, 0].SetValue("Total");

                seriesSheet.Cells[1, 1].SetValue(0);
                seriesSheet.Cells[1, 2].SetValue(total);

                double offset       = total;
                uint   column       = 2;
                uint   seriesRow    = 3;
                uint   connectorRow = 1;
                foreach (BurndownChartCategory category in data.Categories)
                {
                    // set name of category
                    seriesSheet.Cells[column, 0].SetValue(category.Name);
                    connectorSheet.Cells[column, 0].SetValue(category.Name);

                    // set connector of category
                    connectorSheet.Cells[column - 1, connectorRow].SetValue(offset);
                    connectorSheet.Cells[column, connectorRow].SetValue(offset);

                    // set offset of category
                    offset -= category.Series.Sum(s => s.Value);
                    seriesSheet.Cells[column, 1].SetValue(offset);

                    uint seriesIdx   = 0;
                    uint seriesCount = (uint)category.Series.Length;
                    foreach (BurndownChartSeries series in category.Series)
                    {
                        // set name of series
                        seriesSheet.Cells[0, seriesRow + seriesCount - seriesIdx - 1].SetValue(series.Name);

                        // set value of series
                        seriesSheet.Cells[column, seriesRow + seriesCount - seriesIdx - 1].SetValue(Math.Abs(series.Value));

                        ++seriesIdx;
                    }

                    seriesRow += (uint)category.Series.Length;

                    ++connectorRow;
                    ++column;
                }

                CartesianAxes axes = chartSpace.AppendCartesianAxes();

                ILineChart lineChart = chartSpace.InsertLineChart(axes)
                                       .InitializeFromRange(connectorSheet.GetRange(0, 1, 0, connectorRow - 1), connectorSheet.GetRange(1, 0, column - 1, 0));

                IBarChart barChart = chartSpace.InsertBarChart(axes)
                                     .InitializeFromRange(seriesSheet.GetRange(0, 1, 0, seriesRow - 1), seriesSheet.GetRange(1, 0, column - 1, 0))
                                     .SetDirection(BarChartDirection.Column)
                                     .SetGrouping(BarChartGrouping.Stacked)
                                     .SetOverlap(1.0);

                // hide offset series
                barChart.Series[0].Style.SetNoFill();

                if (data.TotalCallback != null)
                {
                    data.TotalCallback(barChart.Series[1].Values[1]);
                }

                int valueIndex  = 1;
                int seriesIndex = 2;
                foreach (BurndownChartCategory category in data.Categories)
                {
                    int seriesIdx = 0;
                    foreach (BurndownChartSeries series in category.Series)
                    {
                        if (series.Callback != null)
                        {
                            IBarChartSeries s = barChart.Series[seriesIndex + category.Series.Length - seriesIdx - 1];
                            series.Callback(s.Values[valueIndex]);
                        }

                        ++seriesIdx;
                    }

                    seriesIndex += category.Series.Length;
                    ++valueIndex;
                }

                axes.CategoryAxis
                .Text.SetFontSize(6)
                .MajorGridlines.Remove();

                axes.ValueAxis
                .SetVisibility(false)
                .MajorGridlines.Remove();

                return(new BurndownChartWizard(chartSpace, data, axes, barChart, lineChart));
            }
        }
Пример #3
0
 public static BurndownChartWizard BuildBurndownChart(this IChartSpace chartSpace, BurndownChartData data)
 {
     return(BurndownChartWizard.BuildBurndownChart(chartSpace, data));
 }