0

I'm trying to use external workbook's data and show it at the chart. I tried like this:

    Workbook externalWorkbook = new XSSFWorkbook(@"..\SomeFolder\ExternalWorkbook.xls");
    Sheet extSheet = externalWorkbook.GetSheetAt(0);

    Chart chart = drawing.CreateChart(anchor);
    LineChartData data = chart.getChartDataFactory.CreateLineChartData();

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

    ChartDataSource<Number> xs = DataSources.FromNumericCellRange(extSheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1));
    ChartDataSource<Number> ys1 = DataSources.FromNumericCellRange(extSheet, new CellRangeAddress(1, 1, 0, NUM_OF_COLUMNS - 1));

    var s1 = data.AddSeries(xs, ys1);
    s1.SetTitle(serie1);

    chart.Plot(data, bottomAxis, leftAxis);

But it doesn't working properly, so at the end, at Excel file in the chart property I have something like:

enter image description here

Instead of:

enter image description here

And obviously it doesn't working normally.
So how do you think, what I'm doing wrong? Maybe I should use some specific function in such case?
Is it even possible to use data from external workbook at the chart with poi apache?

Don chan
  • 35
  • 7
  • 2
    Why not just bring the data into the sheet with the chart then plot from there? A link will get updated so that is not an issue. – Solar Mike Apr 28 '21 at 07:12
  • @SolarMike thank you for the comment, I also thought about that, but, unfortunately it's a specific of my task, I have to take data from external workbook and can't change current workbook with chart. Only show data there. – Don chan Apr 28 '21 at 07:16
  • See https://stackoverflow.com/questions/46508297/why-cant-i-link-one-workbook-to-another-in-apache-poi/46513213#46513213. Note my last edit. – Axel Richter Apr 28 '21 at 11:24

0 Answers0