pablrod / p5-Chart-Plotly

Generate html/javascript charts with perl data using javascript library Plotly.js
MIT License
9 stars 4 forks source link

save_image error in Chart/Kaleido/Plotly.pm line 122 #61

Closed averlon closed 6 months ago

averlon commented 6 months ago

I am not a very experienced perl programmer.

I get these errors:

invalid or malformed request syntax (wrong format) at /home/fx42252/perl5/lib/perl5/Chart/Kaleido/Plotly.pm line 122.

my script:


my $data_in_json = read_json_file("$av_gw_GWDIR/$av_gw_IMAGE1JSON");

my $x_axis = $data_in_json->{domainAxis};
my $y_axis = $data_in_json->{rangeAxis};

my $plot = Chart::Plotly::Plot->new();
foreach my $y_line (keys %{$y_axis->{lines}}) {
    my $scatter = Chart::Plotly::Trace::Scatter->new(
        x    => $x_axis->{data},
        y    => $y_axis->{lines}->{$y_line}->{data},
        name => $y_axis->{lines}->{$y_line}->{legendName}
     );
    $plot->add_trace($scatter);
}

save_image(
    file   => "$av_gw_GWDIR/$av_gw_IMAGE1JPG",        # Referring to a local filesystem path
    plot   => $plot,
    width  => 1024,                   # Sets the image width
    height => 768,                    # Sets the image height
    engine => 'auto'
);

The json-file is:

{
    "title": "Number of automobiles sold per day by manufacturer",
    "domainAxis": {
        "data": ["2020-04-15", "2020-04-16", "2020-04-17", "2020-04-18"],
        "label": "Date"
    },
    "rangeAxis": {
        "lines": {
            "line1": {
                "data": [10,3,5,9],
                "legendName": "Honda"
            },
            "line2": {
                "data": [20,15,8,10],
                "legendName": "Toyota"
            },
            "line3": {
                "data": [6,19,12,4],
                "legendName": "Ford"
            },
            "line4": {
                "data": [16,10,6,12],
                "legendName": "Renault"
            }
        },
        "label": "Numbers of automobiles sold"
    }
}

Taken from : https://dev.to/raigaurav/data-visualization-creating-charts-from-perl-using-plotly-js-chart-plotly-3m48

Cound someone please give me advice what I am doing wrong!

averlon commented 6 months ago

solved it: the output file has to be .png and not .jpg!!!!!