Plotly.Net Image Export

505 views Asked by At

I am trying to save my plotly.Net chart to a jpg but when I try to do that there is no error but the code keeps running forever when it comes to the line maps.SaveJpg(path).
Can any please help thanks?

using Plotly.NET;
using Plotly.NET.ImageExport;

namespace Reports
{
    public class picture
    {

        public static void map()
        {
            string[] y = new string[] { "2.0", "1.5", "5.0", "1.5", "3.0", "5.0" };
            string[] x = new string[] { "Belarus", "Moldova", "Lithuania", "Russia", "Romania", "India" };
            
            var maps = ChartMap.Chart.ChoroplethMap<string, string>(locations: x, y, LocationMode: StyleParam.LocationFormat.CountryNames);
            maps.Show();
            string path = @"C:\Users\axx\Documents\Sucess";
            maps.SaveJPG(path);
            
        }
    
        public static void Main(string[] args)
        {
            map();
        }
    }
}
2

There are 2 answers

1
Andy On

I had exactly the same issue, when I called ToBase64PNGString it just never returned and didn't throw an exception.

The place the code is being called from is within an async block, and when I changed to calling the Async version instead I then got the exception ok. The exception I was getting was DLL load errors. Turned out that PuppeteerSharp was looking for different versions of some MS DLLs. Once I'd sorted out the binding redirects it was ok.

The key here was being able to catch the exceptions. There was something funky going on in my app which meant the exceptions got lost until I changed to the Async version.

0
pal2ie On

It could be that it is not finding the path to the browser for rendering. Use this setting to set the path of the browser. Which may resolve this issue.

Plotly.NET.ImageExport.PuppeteerSharpRendererOptions.localBrowserExecutablePath = "/your/path/here/"