question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to achieve transparent background in pie chart?

See original GitHub issue

Hello. I’ve been trying to generate a piechart as an asset to my pdf template.

I need it to be png with transparent background but I’m only getting black solid colour instead. image

Maybe I’m missing some property or doing something wrong with my colour settings.

Thanks!

Here is my code :

PieChart chart = new PieChartBuilder()
                .width(200)
                .height(200)
                .theme(Styler.ChartTheme.GGPlot2)
                .build();

        chart.getStyler().setLegendVisible(false);

        Color[] sliceColors = new Color[] {
                new Color(238, 88, 88), //red
                new Color(213, 122, 212), //purple
                new Color(106,230, 182), //mentol
                new Color(88,155,238) //baby blue
        };

        chart.getStyler().setSeriesColors(sliceColors);
        chart.getStyler().setChartTitleBoxVisible(false);
        chart.getStyler().setHasAnnotations(false);
        chart.getStyler().setChartBackgroundColor(
                new Color(255,255, 255, 0)
        );
        chart.getStyler().setPlotBackgroundColor(
                new Color(255,255, 255, 0)
        );
        chart.getStyler().setPlotBorderVisible(false);

        chart.addSeries("laptop", 65);
        chart.addSeries("pc", 10);
        chart.addSeries("tel", 12.5);
        chart.addSeries("winda", 12.5);

        BitmapEncoder.saveBitmap(chart, "./Sample_Chart", BitmapEncoder.BitmapFormat.PNG);

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
timmoltercommented, Jul 21, 2020

I thought that the default background had an alpha of 1, which would mean necessitating manually setting to background alpha to 0 to get the desired transparency. If it’s now exporting with no transparency, then that would also be a bug in my opinion. In fact that might be why I set the type to TYPE_INT_RGB originally in:

new BufferedImage(chart.getWidth(), chart.getHeight(), BufferedImage.TYPE_INT_ARGB);
0reactions
Mr14huashaocommented, Jul 21, 2020

@staho @timmolter The code is updated. After the test, the background of the exported image is not black. You do not need to set alpha. This is not a color transparency issue, but a background issue for generating images.

    chart.getStyler().setChartBackgroundColor(new Color(255, 255, 255));
    chart.getStyler().setPlotBackgroundColor(new Color(255, 255, 255));
Read more comments on GitHub >

github_iconTop Results From Across the Web

Make a Transparent Chart in Excel - TeachExcel.com
How to make a Chart transparent so that it blends in with its background and surroundings in Excel. ... Hit Close at the...
Read more >
Center pie chart on its transparent background - Stack Overflow
Is there a way to adjust the code so the circle ends up centered? I've fiddled with making different theme elements blank, to...
Read more >
Make background transparent MS .NET CHART - MSDN
You have to set the ChartArea color to transparent and Chart1.BackColor = Color.Transparent. and if you don't want a white square behind the ......
Read more >
Transparant background (Interactive Charts) - Google Groups
Dear Google Charts users, I trying to get a transparent background on my Google pie chart. Someone posted a solution for the image...
Read more >
How to make a transparent image out of a graph in Excel 2010?
You can select an excel graph and choose color fill > no fill. This will remove the background from it but you can't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found