Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Thu Nov 25, 2021 8:13 pm

Using spire.Office for JAVA 4.11.3 and Jdk13

When I use saveChartAsImage(), the chart (cf file as an attachment) is falling into infinite process.

If I comment line using serie.setUsePrimaryAxis(false); the function is working.

NB. : it is working with other similar chart with secondary axis too.

The file as an attachment is saved for debugging before calling the function.
Attachments
9342f581-2c82-4ba3-99a4-b20980467072_BAR.zip
(10.29 KiB) Downloaded 165 times

QuentinSup
 
Posts: 46
Joined: Mon Oct 18, 2021 9:18 am

Fri Nov 26, 2021 2:12 am

Hello Quentin,

Thank you for your inquiry.
I used saveChartAsImage() to test the Excel file you provided, but didn't find the behavior you mentioned. According to your description, you use our Spire.Office to create a chart and then save the chart as a picture, right? To help us further investigate your issue, please provide the following information. You could attach them here or send them to us via email (support@e-iceblue.com). Thanks in advance.
1) Your complete test code.
2) Your test environment, such as OS info (E.g. Windows 7, 64-bit) and region setting (E.g. China, Chinese).

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Fri Nov 26, 2021 11:32 am

Here code used to create Chart

Code: Select all
    public BufferedImage createChart(Workbook workbook, ChartData data, Double width, Double height) throws Exception {
        if (workbook == null) {
            workbook = new Workbook();
        }
        final Worksheet sheet = workbook.createEmptySheet();
        this.addChartToWorksheet(sheet, data, width, height);

        workbook.saveToFile(UUID.randomUUID() + "_" + data.getType().name() + ".xlsx");

        return workbook.saveChartAsImage(sheet, 0);
    }

    protected void addChartToWorksheet(Worksheet sheet, ChartData data, Double width, Double height) throws Exception {

        final Chart chart = sheet.getCharts().add(formatExcelChartType(data.getType()));
        final DataTable dataTable = createChartDataTable(data);

        sheet.insertDataTable(dataTable, true, 1, 1);

        chart.getPlotArea().getFill().setVisible(false);

        final CellRange cellDataRange =
                sheet.getCellRange(1, 1, dataTable.getRows().size() + 1, dataTable.getColumns().size());

        chart.getPrimaryCategoryAxis().setCategoryLabels(
                sheet.getCellRange(1, data.getLegends() != null ? 2 : 1, 1, dataTable.getColumns().size()));

        //Set region of chart data
        chart.setDataRange(cellDataRange);
        chart.setSeriesDataFromRange(true);

        //Set position of chart
        chart.setLeft(1);
        chart.setTopRow(6);
        chart.setWidth((int) Math.round(width == null ? data.getW() : width));
        chart.setHeight((int) Math.round(height == null ? data.getH() : height));

        //Chart title
        chart.setChartTitle(data.getTitle());
        chart.getChartTitleArea().isBold(true);
        chart.getChartTitleArea().setSize(10);
        chart.setWallsAndGridlines2D(true);

        // Text gray
        final Color textColor = new Color(89, 89, 89);

        chart.getPrimaryValueAxis().getBorder().setCustomLineWeight(0);
        chart.getPrimaryValueAxis().getBorder().setColor(Color.WHITE);
        chart.getPrimaryValueAxis().getFont().setColor(textColor);
        //chart.getPrimaryValueAxis().setAutoTickLabelSpacing(true);
        //chart.getPrimaryValueAxis().setAutoTickMarkSpacing(true);
        chart.getPrimaryValueAxis().getMajorGridLines().getBorder().setColor(new Color(217, 217, 217));
        chart.getPrimaryCategoryAxis().getFont().setColor(textColor);
        chart.getPrimaryCategoryAxis().getBorder().setCustomLineWeight(0);
        chart.getPrimaryCategoryAxis().getBorder().setColor(Color.WHITE);

        // Border
        chart.getChartArea().getBorder().setCustomLineWeight(0);
        chart.getChartArea().getBorder().setColor(new Color(255, 255, 255));

        if (data.getType() != ChartTypeEnum.PIE) {
            chart.hasLegend(data.getLegends() != null);
            chart.getLegend().setPosition(LegendPositionType.Bottom);
        } else {
            chart.hasLegend(true);
            chart.getLegend().setPosition(LegendPositionType.Right);
        }

        //Draw chart with data

        final AtomicInteger iSerie = new AtomicInteger();
        chart.getSeries().forEach(cs -> {
            final ChartSerie s = (ChartSerie) cs;
            final fr.exceliances.easy.service.generation.model.ChartSerie sourceSerie =
                    data.getSeries().get(iSerie.getAndIncrement());
            final Color color = sourceSerie.getColor();

            s.getDataPoints().getDefaultDataPoint().getDataLabels().hasValue(sourceSerie.isShowDataLabels());
            s.getFormat().getFormat3D().setBevelTopType(XLSXChartBevelType.SoftRound);
            s.getFormat().getFormat3D().setBevelTopWidth(12);
            s.getFormat().getFormat3D().setBevelTopHeight(4);

            if (sourceSerie.getNumberFormat() != null) {
                s.getValues().setNumberFormat(sourceSerie.getNumberFormat());
            } else {
                s.getValues().setNumberFormat("# ##0;-# ##0");
            }

            if (sourceSerie.getType() != null) {
                s.setSerieType(sourceSerie.getType());
            }

            if (sourceSerie.isSecondaryAxis()) {
                s.setUsePrimaryAxis(false);
            }

            if (data.getType() != ChartTypeEnum.PIE) {
                s.getFormat().setForeGroundColor(color == null ? CHART_COLORS[iSerie.get() - 1] : color);
                s.getFormat().getOptions().setOverlap(-10);
            }

            if (data.getType() == ChartTypeEnum.BAR_TREND || data.getType() == ChartTypeEnum.BAR) {
                s.getDataLabels().setTextRotationAngle(-45);
            }

            if (data.getType() == ChartTypeEnum.BAR_TREND) {
                final IChartTrendLine chartTrendLine = s.getTrendLines().add(TrendLineType.Linear);
                chartTrendLine.getBorder().setWeight(ChartLineWeightType.Narrow);
                chartTrendLine.getBorder().setColor(new Color(110, 100, 112));
            }

            for (int i = 0; i < s.getPointNumber(); i++) {
                final ChartDataPoint dp = chart.getSeries().get(0).getDataPoints().get(i++);
                dp.getDataLabels().setPosition(DataLabelPositionType.Automatic);
            }

        });

        if (chart.getSeries().size() == 1) {
            final ChartSerie chartSerie = chart.getSeries().get(0);
            final fr.exceliances.easy.service.generation.model.ChartSerie sourceSerie = data.getSeries().get(0);
            for (int i = 0; i < chartSerie.getPointNumber(); i++) {
                final ChartDataPoint dp = chartSerie.getDataPoints().get(i);
                final ChartValue<?> chartValue = sourceSerie.getValues().get(i);
                dp.getDataLabels().getFormat().setBackGroundColor(new Color(40, 40, 40));
                dp.getDataLabels().setColor(Color.DARK_GRAY);
                dp.getDataFormat().getFormat3D().setBevelTopType(XLSXChartBevelType.SoftRound);
                dp.getDataFormat().getFormat3D().setBevelTopWidth(12);
                dp.getDataFormat().getFormat3D().setBevelTopHeight(4);
                dp.getDataFormat()
                        .setForeGroundColor(chartValue.getColor() == null ? CHART_COLORS[i] : chartValue.getColor());
            }
        }
    }

    protected DataTable createChartDataTable(ChartData chartData) throws Exception {
        final DataTable dataTable = new DataTable();
        final DataRowCollection rows = new DataRowCollection(dataTable);

        if (chartData.getLegends() != null) {
            final DataColumn col = new DataColumn();
            col.setColumnName("");
            dataTable.getColumns().add(new DataColumn());
        }

        chartData.getLabels().forEach(l -> {
            final DataColumn col = new DataColumn();
            col.setColumnName(l);
            dataTable.getColumns().add(col);
        });

        final AtomicInteger iSerie = new AtomicInteger();
        for (fr.exceliances.easy.service.generation.model.ChartSerie cs : chartData.getSeries()) {
            final DataRow rowValue = dataTable.newRow();
            final AtomicInteger cellIndx = new AtomicInteger(0);

            if (chartData.getLegends() != null) {
                rowValue.setObject(cellIndx.getAndIncrement(), chartData.getLegends().get(iSerie.getAndIncrement()));
            }

            cs.getValues().forEach(cv -> {
                rowValue.setObject(cellIndx.getAndIncrement(), cv.getValue());
            });
            rows.add(rowValue);
        }
        dataTable.setRows(rows);
        return dataTable;
    }

    protected ExcelChartType formatExcelChartType(ChartTypeEnum type) {
        switch (type) {
            case PIE:
                return ExcelChartType.PieExploded;
            case LINE:
                return ExcelChartType.LineMarkers;
            case BAR:
            case BAR_TREND:
                return ExcelChartType.ColumnClustered;
            default:
                return ExcelChartType.Bar100PercentStacked;
        }
    }


And implementation to ChartData

Code: Select all

        final ChartData data = new ChartData(200, 250, 450, 250);
        final List<String> labels = new ArrayList<>();
        labels.add("SCI IR");
        labels.add("SCI IS");
        data.setLabels(labels);

        final List<String> legends = new ArrayList<>();
        legends.add("Flux de trésorerie nets sur la période (associé)");
        legends.add("VAN **");
        legends.add("TRI *");
        data.setLegends(legends);

        final List<ChartSerie> series = new ArrayList<>();
        ChartSerie serie = new ChartSerie(Arrays.asList(new ChartValue<>(664967.3000000002), new ChartValue<>(714024.6299999999)));
        series.add(serie);

        serie = new ChartSerie(Arrays.asList(new ChartValue<>(114992.18000000001), new ChartValue<>(220174.36)));
        serie.setColor(Color.MAGENTA);
        series.add(serie);

        serie = new ChartSerie(Arrays.asList(new ChartValue<>(0.17113181421731205), new ChartValue<>(0.39447897567122436)));
        serie.setType(ExcelChartType.LineMarkers);
        serie.setSecondaryAxis(true);
        serie.setNumberFormat("0.00%");
        series.add(serie);

        data.setSeries(series);
        data.setType(ChartTypeEnum.BAR);
        return data;


Custom classes are in attachment.
Attachments
classes.zip
(2.3 KiB) Downloaded 164 times

QuentinSup
 
Posts: 46
Joined: Mon Oct 18, 2021 9:18 am

Fri Nov 26, 2021 11:36 am

Important

After doing lot of tests wit different data :

The issue occured when data of the secondary axis generate an axis with maximum is less than 100%

Not working :
Code: Select all
serie = new ChartSerie(Arrays.asList(new ChartValue<>(0.17113181421731205), new ChartValue<>(0.39447897567122436)));


working :
Code: Select all
serie = new ChartSerie(Arrays.asList(new ChartValue<>(0.60), new ChartValue<>(0.90)));

QuentinSup
 
Posts: 46
Joined: Mon Oct 18, 2021 9:18 am

Fri Nov 26, 2021 11:59 am

I confirm : in my case, setting max value to 1 solve the issue.

chart.getSecondaryValueAxis().setMaxValue(1);
chart.getSecondaryValueAxis().setMinValue(0);


I can use it as a workaround but i'm waiting this issue to be fixed !

QuentinSup
 
Posts: 46
Joined: Mon Oct 18, 2021 9:18 am

Mon Nov 29, 2021 9:11 am

Hello,

Thank you for your sharing, and sorry for the late reply as weekend.
I tested your case, but did not reproduce your issue. I have attached my test project, please download and test it on your side. If the problem still exists after the test, please provide your test environment (such as OS info (E.g. Windows 7, 64-bit) and region setting (E.g. China, Chinese)) for our reference. Thanks in advance.

Sincerely,
Annika
E-iceblue support team
Attachments
attachment.zip
(186.72 KiB) Downloaded 163 times
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Mon Nov 29, 2021 10:19 am

Hi,

I've downloaded your project and execute main() : I confirm that I've reproduced the issue (infinite process)

Test environment : Windows 10 Professionnel, version 21H1, 64 bits
Region setting : FRANCE
IntelliJ IDEA 2021 2.2
JDK 13

QuentinSup
 
Posts: 46
Joined: Mon Oct 18, 2021 9:18 am

Tue Nov 30, 2021 2:54 am

Hello,

Thank you for your feedback.
I tested it again in the same environment with the same settings as you, but still did not reproduce your issue. In addition, I also did a test on Windows Server2016, and there was still no problem. Do you directly open my projcet in IntelliJ IDEA 2021 and run it? Could you please test my project again on other computers and inform us of your test results? Looking forward to your test feedback.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Tue Nov 30, 2021 9:28 am

Bonjour,

J'ai testé le projet sur un ordre ordinateur mais avec une configuration similaire (Windows 10 Pro, JDK13 ou JDK1.8 ) : même soucis ! Le process part dans un traitement qui ne se termine jamais...

1. J'ai ouvert le projet dans IntelliJ :
2. en l'état il ne s'exécute pas, il faut déplacer les classes 'Cell' et 'Chart' dans un package com.example.demo
3. j'exécute le main de classe

=> ça ne rend pas la main (avec ou sans mode debug)

Lorsque je mets le debugger sur "Pause", j'atterri dans une classe Spire donc il y a bien un traitement en cours, mais qui ne se termine jamais !

QuentinSup
 
Posts: 46
Joined: Mon Oct 18, 2021 9:18 am

Tue Nov 30, 2021 10:21 am

Hi,

Thank you for your feedback.
I am attaching my test project again, please download it and test it again on your side. I also attached the screen recording of my test project (refer to RecordScreen.mp4 in [url=/attachments(27608).zip]the attachment[/url]). If there is still a problem, please provide the screen recording when you test the project to us for further investigate your problem.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Tue Nov 30, 2021 11:44 am

Hi,

I've watched the video and tried do the follow the same way.

I've made two video to show the issues with infinite process and export PIE as image problem.

The videos are too heavy to be uploaded so you can download them following this wetransfer link https://we.tl/t-ovoVFoISY8

QuentinSup
 
Posts: 46
Joined: Mon Oct 18, 2021 9:18 am

Tue Nov 30, 2021 12:04 pm

Important

If I change de locale default as
Code: Select all
Locale.setDefault(Locale.CHINA);


I've no more issues (infinite process or image export).

So to reproduce my issues, you should add this :
Code: Select all
Locale.setDefault(Locale.FRANCE);

QuentinSup
 
Posts: 46
Joined: Mon Oct 18, 2021 9:18 am

Wed Dec 01, 2021 3:46 am

Hi,

Thank you for your feedback.
By adding "Locale.setDefault(Locale.FRANCE)", I did reproduce your issue(process infinite loop). I have logged the issue into our bug tracking system with the ticket number SPIREXLS-3565. Our development team will investigate and fix it. Once it is resolved, I will inform you in time. Sorry for the inconvenience caused.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Tue Dec 21, 2021 9:58 am

Hello,

Thank you for your patience.
Glad to inform that we just released Spire.Office for Java Version:4.12.2 which fixed the issue SPIREXLS-3565, please download it from the following links to test.
Website link: https://www.e-iceblue.com/Download/office-for-java.html
Maven link: https://repo.e-iceblue.com/nexus/conten ... ce/4.12.2/
In addition, please add the following code in pom.xml to avoid the project throwing exceptions.
Code: Select all
<dependency>
<groupId>org.glassfish.corba</groupId>
<artifactId>glassfish-corba-omgapi</artifactId>
<version>4.2.1</version>
</dependency>

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.XLS

cron