ASE Home Page Products Download Purchase Support About ASE
ChartDirector General
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Charts show in URL, but will not save to file
Posted by rpetras on Mar-23-2012 04:48
Hi, I'm experiencing an odd problem.

I've been using ChartDirector (Perl Version) for years to display to web pages using the :

        binmode(STDOUT);
        print "Content-type: image/png\\n\\n";
        print $c->makeChart2($perlchartdir::PNG);

style of output code.  This works fine.



We recently got a requirement to save off a few charts to be emailed at a later time.

I adjusted the output code as follows:

#Output the chart
    if ($saveName) {
        $c->makeChart("/tmp/$saveName.png");
    } else {
        binmode(STDOUT);
        print "Content-type: image/png\\n\\n";
        print $c->makeChart2($perlchartdir::PNG);
    }


So, if the chart comes in with a name, it should save it to /tmp/<name>.png, which seems simple enough.

However, it is not saving.

If I simplify to something like :

#Output the chart
    if ($saveName) {
        $c->makeChart("/tmp/test1.png");
    } else {
        binmode(STDOUT);
        print "Content-type: image/png\\n\\n";
        print $c->makeChart2($perlchartdir::PNG);
    }

I can, at least, get that to work ... but not consistently.

If I run the above without the saveName variable, view the chart, THEN run with the saveName variable, I can get it to output a file.

This behavior seems inconsistent to me.

I've checked simple things like file permissions etc.

So, ultimately, I need to be able to output to the web sometimes, and save to files sometimes.

Any help would be appreciated.

  Re: Charts show in URL, but will not save to file
Posted by Peter Kwan on Mar-23-2012 23:31
Hi rpetras,

In theory, ChartDirector should not be able to behave differently for hard coded file name versus filename in a variable. It is because the variable is processed by Perl, not by ChartDirector. By the time ChartDirector received the filename from Perl, it is already the final text string. ChartDirector cannot determine whether the text is original hard coded in the Perl source code, or from a variable, and so it cannot behave differently.

For your case, to diagnose the problem, may be you can consider to include the filename in the chart, so that you can see the filename. For example:

    if ($saveName) {
        $c->addTitle(("/tmp/$saveName.png");
        $c->makeChart("/tmp/testing.png");
        $c->makeChart("/tmp/$saveName.png");
    } else {
        $c->makeChart("/tmp/bbbb.png");
        binmode(STDOUT);
        print "Content-type: image/png\\n\\n";
        print $c->makeChart2($perlchartdir::PNG);
    }

In the above, the filename will be included in the chart title. The chart will be saved to both a hard coded filename "/tmp/testing.png" and the "/tmp/$saveName.png". If you cannot find the file "/tmp/$saveName.png", you may still be able to find "/tmp/testing.png", and can view it to see what is the actual file name "/tmp/$saveName.png". This can help to confirm if the filename is what you expect. Furthermore, the code will save the chart to "/tmp/bbbb.png" even if the "else" part is executed. This can help to double check if the "if" part is being executed at all.

Another method is to just Perl code to store the chart image, like:

    if ($saveName) {
        open(my $out, '>:raw', "/tmp/$saveName.png");
        print $out $chart->makeChart2($perlchartdir::PNG);
        close($out);
    }

In the above code, the file is created by Perl, not by ChartDirector. Assuming your CGI script has sufficient priviledge to create the file, and that "/tmp/$saveName.png" is a vaild filename, the file should always be created.

Hope this can help.

Regards
Peter Kwan