static void CreateChart(IDrawing drawing, ISheet sheet, IClientAnchor anchor, string serie1, string serie2) { IChart chart = drawing.CreateChart(anchor); IChartLegend legend = chart.GetOrCreateLegend(); legend.Position = LegendPosition.TopRight; ILineChartData <double, double> data = chart.ChartDataFactory.CreateLineChartData <double, double>(); // Use a category axis for the bottom axis. IChartAxis bottomAxis = chart.GetChartAxisFactory().CreateCategoryAxis(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.AddSeries(xs, ys1); s1.SetTitle(serie1); var s2 = data.AddSeries(xs, ys2); s2.SetTitle(serie2); chart.Plot(data, bottomAxis, leftAxis); }
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.GetChartAxisFactory().CreateValueAxis(AxisPosition.BOTTOM); IChartAxis leftAxis = chart.GetChartAxisFactory().CreateValueAxis(AxisPosition.LEFT); IScatterChartData scatterChartData = chart.GetChartDataFactory().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); }
static void Main(string[] args) { 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 = LegendPosition.TopRight; ILineChartData <double, double> data = chart.GetChartDataFactory().CreateLineChartData <double, double>(); // Use a category axis for the bottom axis. IChartAxis bottomAxis = chart.GetChartAxisFactory().CreateCategoryAxis(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); using (FileStream fs = File.Create("test.xlsx")) { wb.Write(fs); } }
public TestXSSFChartAxis() { IWorkbook wb = new XSSFWorkbook(); ISheet sheet = wb.CreateSheet(); IDrawing Drawing = sheet.CreateDrawingPatriarch(); IClientAnchor anchor = Drawing.CreateAnchor(0, 0, 0, 0, 1, 1, 10, 30); IChart chart = Drawing.CreateChart(anchor); axis = chart.GetChartAxisFactory().CreateValueAxis(AxisPosition.Bottom); }
public void TestAccessMethods() { IWorkbook wb = new XSSFWorkbook(); ISheet sheet = wb.CreateSheet(); IDrawing Drawing = sheet.CreateDrawingPatriarch(); IClientAnchor anchor = Drawing.CreateAnchor(0, 0, 0, 0, 1, 1, 10, 30); IChart chart = Drawing.CreateChart(anchor); IValueAxis axis = chart.GetChartAxisFactory().CreateValueAxis(AxisPosition.BOTTOM); axis.SetCrossBetween(AxisCrossBetween.MIDPOINT_CATEGORY); Assert.AreEqual(axis.GetCrossBetween(), AxisCrossBetween.MIDPOINT_CATEGORY); axis.SetCrosses(AxisCrosses.AUTO_ZERO); Assert.AreEqual(axis.GetCrosses(), AxisCrosses.AUTO_ZERO); Assert.AreEqual(chart.GetAxis().Count, 1); }