예제 #1
0
        private IWorkbook CreateWorkbookWithChart()
        {
            IWorkbook wb             = new XSSFWorkbook();
            ISheet    sheet          = wb.CreateSheet("linechart");
            int       NUM_OF_ROWS    = 3;
            int       NUM_OF_COLUMNS = 10;

            // Create a row and Put some cells in it. Rows are 0 based.
            IRow  row;
            ICell cell;

            for (int rowIndex = 0; rowIndex < NUM_OF_ROWS; rowIndex++)
            {
                row = sheet.CreateRow((short)rowIndex);
                for (int colIndex = 0; colIndex < NUM_OF_COLUMNS; colIndex++)
                {
                    cell = row.CreateCell((short)colIndex);
                    cell.SetCellValue(colIndex * (rowIndex + 1));
                }
            }

            IDrawing      Drawing = sheet.CreateDrawingPatriarch();
            IClientAnchor anchor  = Drawing.CreateAnchor(0, 0, 0, 0, 0, 5, 10, 15);

            IChart       chart  = Drawing.CreateChart(anchor);
            IChartLegend legend = chart.GetOrCreateLegend();

            legend.Position = (/*setter*/ LegendPosition.TopRight);

            ILineChartData <double, double> data = chart.ChartDataFactory.CreateLineChartData <double, double>();

            // Use a category axis for the bottom axis.
            IChartAxis bottomAxis = chart.ChartAxisFactory.CreateCategoryAxis(AxisPosition.Bottom);
            IValueAxis leftAxis   = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Left);

            leftAxis.Crosses = (/*setter*/ AxisCrosses.AutoZero);

            IChartDataSource <double> xs  = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1));
            IChartDataSource <double> ys1 = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(1, 1, 0, NUM_OF_COLUMNS - 1));
            IChartDataSource <double> ys2 = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(2, 2, 0, NUM_OF_COLUMNS - 1));

            data.AddSeries(xs, ys1);
            data.AddSeries(xs, ys2);

            chart.Plot(data, bottomAxis, leftAxis);

            return(wb);
        }
예제 #2
0
        public void TestOneSeriePlot()
        {
            IWorkbook     wb      = new XSSFWorkbook();
            ISheet        sheet   = new SheetBuilder(wb, plotData).Build();
            IDrawing      Drawing = sheet.CreateDrawingPatriarch();
            IClientAnchor anchor  = Drawing.CreateAnchor(0, 0, 0, 0, 1, 1, 10, 30);
            IChart        chart   = Drawing.CreateChart(anchor);

            IChartAxis bottomAxis = chart.ChartAxisFactory.CreateCategoryAxis(AxisPosition.Bottom);
            IChartAxis leftAxis   = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Left);

            ILineChartData <string, double> lineChartData =
                chart.ChartDataFactory.CreateLineChartData <string, double>();

            IChartDataSource <String>         xs     = DataSources.FromStringCellRange(sheet, CellRangeAddress.ValueOf("A1:J1"));
            IChartDataSource <double>         ys     = DataSources.FromNumericCellRange(sheet, CellRangeAddress.ValueOf("A2:J2"));
            ILineChartSeries <string, double> series = lineChartData.AddSeries(xs, ys);

            Assert.IsNotNull(series);
            Assert.AreEqual(1, lineChartData.GetSeries().Count);
            Assert.IsTrue(lineChartData.GetSeries().Contains(series));

            chart.Plot(lineChartData, bottomAxis, leftAxis);
        }
예제 #3
0
        private static void FillChartDataCells(ISheet sheet, int rowNum, IReadOnlyList <double> iterationsList, IChartDataSource <string> xAxis, ILineChartData <string, double> data)
        {
            var row = sheet.CreateRow(rowNum);

            for (int i = 0; i < iterationsList.Count; i++)
            {
                row.CreateCell(i).SetCellValue(iterationsList[i]);
            }

            var yAxis = DataSources.FromNumericCellRange(sheet,
                                                         new CellRangeAddress(rowNum, rowNum, 0, iterationsList.Count - 1));

            data.AddSeries(xAxis, yAxis).SetTitle(((Methods)(rowNum - 1)).ToString());
        }