private static void BuildNumRef <T>(CT_NumRef ctNumRef, IChartDataSource <T> dataSource) { ctNumRef.f = (dataSource.FormulaString); CT_NumData cache = ctNumRef.AddNewNumCache(); FillNumCache(cache, dataSource); }
/** * Builds CTAxDataSource object content from POI ChartDataSource. * @param ctAxDataSource OOXML data source to build * @param dataSource POI data source to use */ public static void BuildAxDataSource <T>(CT_AxDataSource ctAxDataSource, IChartDataSource <T> dataSource) { if (dataSource.IsNumeric) { if (dataSource.IsReference) { BuildNumRef(ctAxDataSource.AddNewNumRef(), dataSource); } else { BuildNumLit(ctAxDataSource.AddNewNumLit(), dataSource); } } else { if (dataSource.IsReference) { BuildStrRef(ctAxDataSource.AddNewStrRef(), dataSource); } else { BuildStrLit(ctAxDataSource.AddNewStrLit(), dataSource); } } }
private static void BuildStrRef <T>(CT_StrRef ctStrRef, IChartDataSource <T> dataSource) { ctStrRef.f = (dataSource.FormulaString); CT_StrData cache = ctStrRef.AddNewStrCache(); FillStringCache(cache, dataSource); }
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); }
private static void CreateChart(ISheet sheet, IDrawing drawing, IClientAnchor anchor, string serieTitle, int startDataRow, int endDataRow, int columnIndex) { XSSFChart chart = (XSSFChart)drawing.CreateChart(anchor); IBarChartData <string, double> barChartData = chart.ChartDataFactory.CreateBarChartData <string, double>(); IChartLegend legend = chart.GetOrCreateLegend(); legend.Position = LegendPosition.Bottom; IChartAxis bottomAxis = chart.ChartAxisFactory.CreateCategoryAxis(AxisPosition.Bottom); bottomAxis.MajorTickMark = AxisTickMark.None; IValueAxis leftAxis = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Left); leftAxis.Crosses = AxisCrosses.AutoZero; leftAxis.SetCrossBetween(AxisCrossBetween.Between); IChartDataSource <string> categoryAxis = DataSources.FromStringCellRange(sheet, new CellRangeAddress(startDataRow, endDataRow, 0, 0)); IChartDataSource <double> valueAxis = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(startDataRow, endDataRow, columnIndex, columnIndex)); var serie = barChartData.AddSeries(categoryAxis, valueAxis); serie.SetTitle(serieTitle); chart.Plot(barChartData, bottomAxis, leftAxis); }
internal Serie(int id, int order, IChartDataSource <Tx> xs, IChartDataSource <Ty> ys) { this.id = id; this.order = order; this.xs = xs; this.ys = ys; }
public void TestIobExceptionOnInvalidIndex() { IWorkbook wb = new HSSFWorkbook(); ISheet sheet = new SheetBuilder(wb, numericCells).Build(); CellRangeAddress rangeAddress = CellRangeAddress.ValueOf("A2:E2"); IChartDataSource <double> numDataSource = DataSources.FromNumericCellRange(sheet, rangeAddress); IndexOutOfRangeException exception = null; try { numDataSource.GetPointAt(-1); } catch (IndexOutOfRangeException e) { exception = e; } Assert.IsNotNull(exception); exception = null; try { numDataSource.GetPointAt(numDataSource.PointCount); } catch (IndexOutOfRangeException e) { exception = e; } Assert.IsNotNull(exception); }
static void CreateChart(IDrawing drawing, ISheet sheet, IClientAnchor anchor, string serie1, string serie2, bool enableMajorGridline = false) { XSSFChart chart = (XSSFChart)drawing.CreateChart(anchor); chart.SetTitle("Test 1"); 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.ChartAxisFactory.CreateCategoryAxis(AxisPosition.Bottom); IValueAxis leftAxis = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Left); leftAxis.Crosses = 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); //add major gridline, available since NPOI 2.5.5 var plotArea = chart.GetCTChart().plotArea; plotArea.catAx[0].AddNewMajorGridlines(); plotArea.valAx[0].AddNewMajorGridlines(); }
/// <summary> /// Wipes out and re-loads boxes collection from the data store. /// </summary> public void ReloadBoxes([NotNull] IChartDataSource source) { m_boxesByDataId.Clear(); m_boxesById.Clear(); m_lastBoxId = 0; // generate system root box SystemRoot = Box.Special(++m_lastBoxId, Box.None, true); m_boxesById.Add(SystemRoot.Id, SystemRoot); var map = new Dictionary <string, int>(); // generate identifiers mapping, need this because data comes in random order foreach (var dataId in source.AllDataItemIds) { map.Add(dataId, NextBoxId()); } // add data-bound boxes var getDataItem = source.GetDataItemFunc; foreach (var dataId in source.AllDataItemIds) { var parentDataId = string.IsNullOrEmpty(dataId) ? null : source.GetParentKeyFunc(dataId); var visualParentId = string.IsNullOrEmpty(parentDataId) ? SystemRoot.Id : map[parentDataId]; AddBox(dataId, map[dataId], visualParentId, getDataItem(dataId).IsAssistant); } }
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.CreateValueAxis(AxisPosition.Bottom); IChartAxis leftAxis = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Left); IScatterChartData <string, double> scatterChartData = chart.ChartDataFactory.CreateScatterChartData <string, double>(); IChartDataSource <String> xs = DataSources.FromStringCellRange(sheet, CellRangeAddress.ValueOf("A1:J1")); IChartDataSource <double> ys = DataSources.FromNumericCellRange(sheet, CellRangeAddress.ValueOf("A2:J2")); IScatterChartSeries <string, double> series = scatterChartData.AddSeries(xs, ys); Assert.IsNotNull(series); Assert.AreEqual(1, scatterChartData.GetSeries().Count); Assert.IsTrue(scatterChartData.GetSeries().Contains(series)); chart.Plot(scatterChartData, bottomAxis, leftAxis); }
private void AssertDataSourceIsEqualToArray <T>(IChartDataSource <T> ds, T[] array) { Assert.AreEqual(ds.PointCount, array.Length); for (int i = 0; i < array.Length; ++i) { Assert.AreEqual(ds.GetPointAt(i), array[i]); } }
/// <summary> /// 创建一个图表实例 /// </summary> /// <param name="excelChart"></param> /// <param name="sheet"></param> private void CreateChart(NPOIExcelChart excelChart, ISheet sheet, int startRow, int endRow) { if (_excelType != NPOIExcelType.XLS) { throw new NotImplementedException("只支持.xls文件作图"); } IDrawing drawing = sheet.CreateDrawingPatriarch(); IClientAnchor anchor = drawing.CreateAnchor(0, 0, 0, 0, 0, startRow, excelChart.Axis.Count, endRow); XSSFChart chart = drawing.CreateChart(anchor) as XSSFChart; chart.Title.String = excelChart.Title; IChartLegend legend = chart.GetOrCreateLegend(); legend.Position = LegendPosition.TopRight; //坐标轴 var axis = chart.ChartAxisFactory.CreateCategoryAxis(AxisPosition.Bottom); axis.IsVisible = true; //值轴 var data = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Left); data.IsVisible = true; data.Crosses = (AxisCrosses.AutoZero); IChartDataSource <string> xs = DataSources.FromArray <string>(excelChart.Axis.ToArray()); switch (excelChart.ExcelChartType) { case NPOIExcelChartType.Bar: var chartBarData = chart.ChartDataFactory.CreateBarChartData <string, double>(); foreach (var item in excelChart.Data) { var curData = DataSources.FromArray <double>(item.Value.ToArray()); var curSeries = chartBarData.AddSeries(xs, curData); curSeries.SetTitle(item.Key); } chart.Plot(chartBarData, axis, data); return; case NPOIExcelChartType.Line: var chartLineData = chart.ChartDataFactory.CreateLineChartData <string, double>(); foreach (var item in excelChart.Data) { var curData = DataSources.FromArray <double>(item.Value.ToArray()); var curSeries = chartLineData.AddSeries(xs, curData); curSeries.SetTitle(item.Key); } chart.Plot(chartLineData, axis, data); break; default: break; } }
internal Serie(int id, int order, IChartDataSource <Tx> categories, IChartDataSource <Ty> values) { this.id = id; this.order = order; this.categories = categories; this.values = values; }
public void TestStringArrayDataSource() { String[] strings = new String[] { "one", "two", "three", "four", "five" }; IChartDataSource <String> stringDataSource = DataSources.FromArray(strings); Assert.IsFalse(stringDataSource.IsNumeric); Assert.IsFalse(stringDataSource.IsReference); AssertDataSourceIsEqualToArray(stringDataSource, strings); }
public void TestNumericArrayDataSource() { Double[] doubles = new Double[] { 1.0, 2.0, 3.0, 4.0, 5.0 }; IChartDataSource <Double> doubleDataSource = DataSources.FromArray(doubles); Assert.IsTrue(doubleDataSource.IsNumeric); Assert.IsFalse(doubleDataSource.IsReference); AssertDataSourceIsEqualToArray(doubleDataSource, doubles); }
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); } }
internal Series(int id, int order, IChartDataSource <Tx> xs, IChartDataSource <Ty> ys) : base() { this.id = id; this.order = order; //this.useCache = true; this.xs = xs; this.ys = ys; }
public static void BuildNumDataSource <T>(CT_NumDataSource ctNumDataSource, IChartDataSource <T> dataSource) { if (dataSource.IsReference) { XSSFChartUtil.BuildNumRef <T>(ctNumDataSource.AddNewNumRef(), dataSource); } else { XSSFChartUtil.BuildNumLit <T>(ctNumDataSource.AddNewNumLit(), dataSource); } }
public void GenaretionChart() { FileStream RfileStream = new FileStream("D:\\test.xlsx", FileMode.Open, FileAccess.Read); //建立讀取資料的FileStream XSSFWorkbook wb = new XSSFWorkbook(RfileStream); //讀取檔案內的Workbook物件 ISheet Wsheet = wb.GetSheetAt(1); //選擇圖表存放的sheet ISheet Rsheet = wb.GetSheetAt(0); //選擇資料來源的sheet IDrawing drawing = Wsheet.CreateDrawingPatriarch(); //sheet產生drawing物件 IClientAnchor clientAnchor = drawing.CreateAnchor(0, 0, 0, 0, 0, 0, 5, 10); //設定圖表位置 IChart chart = drawing.CreateChart(clientAnchor); //產生chart物件 IChartLegend legend = chart.GetOrCreateLegend(); //還沒研究出這行在做甚麼 legend.Position = LegendPosition.TopRight; ILineChartData <double, double> data = chart.ChartDataFactory.CreateLineChartData <double, double>(); //產生存放資料的物件(資料型態為double) IChartAxis bottomAxis = chart.ChartAxisFactory.CreateCategoryAxis(AxisPosition.Bottom); //設定X軸 IValueAxis leftAxis = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Left); //設定Y軸 bottomAxis.Crosses = AxisCrosses.AutoZero; //設定X軸數值開始為0 leftAxis.Crosses = AxisCrosses.AutoZero; //設定Y軸數值開始為0 IChartDataSource <double> xs = DataSources.FromNumericCellRange(Rsheet, new CellRangeAddress(0, 4, 0, 0)); //取得要讀取sheet的資料位置(CellRangeAddress(first_row,end_row, first_column, end_column)) //x軸資料 IChartDataSource <double> ys1 = DataSources.FromNumericCellRange(Rsheet, new CellRangeAddress(0, 4, 1, 1)); //第一條y軸資料 IChartDataSource <double> ys2 = DataSources.FromNumericCellRange(Rsheet, new CellRangeAddress(0, 4, 2, 2)); //第二條y軸資料 data.AddSeries(xs, ys1); data.AddSeries(xs, ys2); //加入到data chart.Plot(data, bottomAxis, leftAxis); //加入到chart FileStream WfileStream = new FileStream("D:\\test.xlsx", FileMode.Create, FileAccess.Write); //建立寫入資料的FileStream wb.Write(WfileStream); //將workbook寫入資料 RfileStream.Close(); //關閉FileStream WfileStream.Close(); //關閉FileStream }
public ILineChartSerie <Tx, Ty> AddSerie(IChartDataSource <Tx> categoryAxisData, IChartDataSource <Ty> values) { if (!values.IsNumeric) { throw new ArgumentException("Value data source must be numeric."); } int numOfSeries = series.Count; Serie newSerie = new Serie(numOfSeries, numOfSeries, categoryAxisData, values); series.Add(newSerie); return(newSerie); }
public IScatterChartSeries <Tx, Ty> AddSeries(IChartDataSource <Tx> xs, IChartDataSource <Ty> ys) { if (!ys.IsNumeric) { throw new ArgumentException("Y axis data source must be numeric."); } int numOfSeries = series.Count; Series newSerie = new Series(numOfSeries, numOfSeries, xs, ys); series.Add(newSerie); return(newSerie); }
public IScatterChartSerie <Tx, Ty> AddSerie(IChartDataSource <Tx> xs, IChartDataSource <Ty> ys) { if (!ys.IsNumeric) { throw new ArgumentException("Y axis data source must be numeric."); } int count = this.series.Count; XSSFScatterChartData <Tx, Ty> .Serie serie = new XSSFScatterChartData <Tx, Ty> .Serie(count, count, xs, ys); this.series.Add((IScatterChartSerie <Tx, Ty>)serie); return((IScatterChartSerie <Tx, Ty>)serie); }
public void Main() { 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.ChartDataFactory.CreateScatterChartData <double, double>(); IValueAxis bottomAxis = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Bottom); IValueAxis leftAxis = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Left); leftAxis.Crosses = 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); // Write the output to a file FileStream sw = File.Create("test.xlsx"); wb.Write(sw); sw.Close(); }
public void TestStringCellDataSource() { IWorkbook wb = new HSSFWorkbook(); ISheet sheet = new SheetBuilder(wb, stringCells).Build(); CellRangeAddress numCellRange = CellRangeAddress.ValueOf("A2:E2"); IChartDataSource <String> numDataSource = DataSources.FromStringCellRange(sheet, numCellRange); Assert.IsTrue(numDataSource.IsReference); Assert.IsFalse(numDataSource.IsNumeric); Assert.AreEqual(numericCells[0].Length, numDataSource.PointCount); for (int i = 0; i < stringCells[1].Length; ++i) { Assert.AreEqual(stringCells[1][i], numDataSource.GetPointAt(i)); } }
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); }
private static void FillNumCache <T>(CT_NumData cache, IChartDataSource <T> dataSource) { int numOfPoints = dataSource.PointCount; cache.AddNewPtCount().val = (uint)(numOfPoints); for (int i = 0; i < numOfPoints; ++i) { double value = Convert.ToDouble(dataSource.GetPointAt(i)); if (!double.IsNaN(value)) { CT_NumVal ctNumVal = cache.AddNewPt(); ctNumVal.idx = (uint)(i); ctNumVal.v = (value.ToString()); } } }
private static void FillStringCache <T>(CT_StrData cache, IChartDataSource <T> dataSource) { int pointCount = dataSource.PointCount; cache.AddNewPtCount().val = (uint)pointCount; for (int index = 0; index < pointCount; ++index) { object pointAt = (object)dataSource.GetPointAt(index); if (pointAt != null) { CT_StrVal ctStrVal = cache.AddNewPt(); ctStrVal.idx = (uint)index; ctStrVal.v = pointAt.ToString(); } } }
private static void FillNumCache <T>(CT_NumData cache, IChartDataSource <T> dataSource) { int pointCount = dataSource.PointCount; cache.AddNewPtCount().val = (uint)pointCount; for (int index = 0; index < pointCount; ++index) { double d = Convert.ToDouble((object)dataSource.GetPointAt(index)); if (!double.IsNaN(d)) { CT_NumVal ctNumVal = cache.AddNewPt(); ctNumVal.idx = (uint)index; ctNumVal.v = d.ToString(); } } }
public void TestNumericCellDataSource() { IWorkbook wb = new HSSFWorkbook(); ISheet sheet = new SheetBuilder(wb, numericCells).Build(); CellRangeAddress numCellRange = CellRangeAddress.ValueOf("A2:E2"); IChartDataSource <double> numDataSource = DataSources.FromNumericCellRange(sheet, numCellRange); Assert.IsTrue(numDataSource.IsReference); Assert.IsTrue(numDataSource.IsNumeric); Assert.AreEqual(numericCells[0].Length, numDataSource.PointCount); for (int i = 0; i < numericCells[0].Length; ++i) { Assert.AreEqual(((double)numericCells[0][i]) * 2, numDataSource.GetPointAt(i), 0.00001); } }
private static void FillStringCache <T>(CT_StrData cache, IChartDataSource <T> dataSource) { int numOfPoints = dataSource.PointCount; cache.AddNewPtCount().val = (uint)(numOfPoints); for (int i = 0; i < numOfPoints; ++i) { object value = dataSource.GetPointAt(i); if (value != null) { CT_StrVal ctStrVal = cache.AddNewPt(); ctStrVal.idx = (uint)(i); ctStrVal.v = (value.ToString()); } } }