static void Main(string[] args) { IWorkbook wb = new XSSFWorkbook(); ISheet sheet = wb.CreateSheet("Sheet 1"); 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 = (LegendPosition.TopRight); IScatterChartData <double, double> data = chart.GetChartDataFactory().CreateScatterChartData <double, double>(); IValueAxis bottomAxis = chart.GetChartAxisFactory().CreateValueAxis(AxisPosition.Bottom); IValueAxis leftAxis = chart.GetChartAxisFactory().CreateValueAxis(AxisPosition.Left); leftAxis.SetCrosses(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)); var s1 = data.AddSerie(xs, ys1); s1.SetTitle("title1"); var s2 = data.AddSerie(xs, ys2); s2.SetTitle("title2"); chart.Plot(data, bottomAxis, leftAxis); // Write the output to a file FileStream sw = File.Create("test.xlsx"); wb.Write(sw); sw.Close(); }
public void TestFormulaCache() { 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.CreateValueAxis(AxisPosition.Bottom); IChartAxis leftAxis = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Left); IScatterChartData scatterChartData = chart.ChartDataFactory.CreateScatterChartData(); DataMarker xMarker = new DataMarker(sheet, CellRangeAddress.ValueOf("A1:E1")); DataMarker yMarker = new DataMarker(sheet, CellRangeAddress.ValueOf("A2:E2")); IScatterChartSerie serie = scatterChartData.AddSerie(xMarker, yMarker); chart.Plot(scatterChartData, bottomAxis, leftAxis); XSSFScatterChartData.Serie xssfScatterSerie = (XSSFScatterChartData.Serie)serie; XSSFNumberCache yCache = xssfScatterSerie.LastCalculatedYCache; Assert.AreEqual(5, yCache.PointCount); Assert.AreEqual(4.0, yCache.GetValueAt(3), 0.00001); Assert.AreEqual(16.0, yCache.GetValueAt(5), 0.00001); }
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.GetChartAxisFactory().CreateValueAxis(AxisPosition.Bottom); IChartAxis leftAxis = chart.GetChartAxisFactory().CreateValueAxis(AxisPosition.Left); IScatterChartData <string, double> scatterChartData = chart.GetChartDataFactory().CreateScatterChartData <string, double>(); IChartDataSource <String> xs = DataSources.FromStringCellRange(sheet, CellRangeAddress.ValueOf("A1:J1")); IChartDataSource <double> ys = DataSources.FromNumericCellRange(sheet, CellRangeAddress.ValueOf("A2:J2")); IScatterChartSerie <string, double> serie = scatterChartData.AddSerie(xs, ys); Assert.IsNotNull(serie); Assert.AreEqual(1, scatterChartData.GetSeries().Count); Assert.IsTrue(scatterChartData.GetSeries().Contains(serie)); chart.Plot(scatterChartData, bottomAxis, leftAxis); }