|
perl $c->makeTmpFile multiple charts on the same page. |
Posted by Donavon on Feb-12-2013 06:41 |
|
Hello..
I found an example for ASP/VBScript using makeSession but not perl. Any assistance would be greatly appreciated..
How do I put multiple (pie) charts on the same page using $c->makeTmpFile.
Thank You,
~Donavon |
Re: perl $c->makeTmpFile multiple charts on the same page. |
Posted by Peter Kwan on Feb-12-2013 22:34 |
|
Hi Donavon,
Session variables is a feature of the web framework, not ChartDirector. In ASP/VBScript, the web framework is ASP (the VBScript is the programming language). The makeSession method uses the session variable support of the ASP framework to store the chart in a session variable. You can see that the BaseChart.makeSession method requires the ASP Session object as one of its arguments.
In Perl, there is no standard web framework apart from CGI. The CGI framework does not support session variables. If you are not using CGI but using another web framework that supports session variables, you can always store the chart image to the session variable (that is, store the output from BaseChart.makeChart2). For details, you would need to refer to the documentation on the web framework you are using.
Hope this can help.
Regards
Peter Kwan |
Re: perl $c->makeTmpFile multiple charts on the same page. |
Posted by Donavon on Feb-13-2013 02:36 |
|
Hello Peter...
Sorry for the confusion.
I don't want to use session variables. That is the only example I found online that sort of relates to my issue.
I want to use $c->makeTmpFile
Here is the code for what I figured out for:
- perl (perlchartdir.pm)
- Multiple Charts per page
- Image map ($c->getHTMLImageMap)
- Temporary File ($c->makeTmpFile)
If there is a better way to do it please let me know.
Thank You,
~Donavon
<code>
#!/usr/bin/perl
use perlchartdir;
print "Content-type: text/html\\n\\n";
print ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title>Chart Director</title>
</head>
<body>';
$title = 'Chart #1';
@data = (1,2,3);
@labels = ('label 1', 'label 2', 'label 3');
# Create a PieChart object of size 450 x 270 pixels
$c = new PieChart(450, 270);
$c->addTitle("$title");
# Set the center of the pie at (150, 100) and the radius to 80 pixels
$c->setPieSize(150, 140, 95);
# add a legend box where the top left corner is at (330, 50)
$c->addLegend(300, 60);
# modify the sector label format to show percentages only
$c->setLabelFormat("{percent}%");
# Set the pie data and the pie labels
$c->setData(\\@data, \\@labels);
# Use rounded edge shading, with a 1 pixel white (FFFFFF) border
$c->setSectorStyle($perlchartdir::RoundedEdgeShading, 0xffffff, 1);
# Create the image and save it in a temporary location my
$chart1URL = $c->makeTmpFile("/tmp/tmpcharts");
# Create an image map for the chart my
$imageMap1 = $c->getHTMLImageMap("detail.pl?", "", "title='{label} : {value} : {percent}%'","");
print '
<img src="/processes/getchart.pl?img=/tmp/tmpcharts/' . $chart1URL . '" border="0" usemap="#map1">
<map name="map1">' . $imageMap1 . '</map> ';
print '<hr />';
$title = 'Chart #2';
@data = (2,4,6,8);
@labels = ('label 4', 'label 5', 'label 6', 'label 7');
# Create a PieChart object of size 450 x 270 pixels
$c = new PieChart(450, 270);
$c->addTitle("$title");
# Set the center of the pie at (150, 100) and the radius to 80 pixels
$c->setPieSize(150, 140, 95);
# add a legend box where the top left corner is at (330, 50)
$c->addLegend(300, 60);
# modify the sector label format to show percentages only
$c->setLabelFormat("{percent}%");
# Set the pie data and the pie labels
$c->setData(\\@data, \\@labels);
# Use rounded edge shading, with a 1 pixel white (FFFFFF) border
$c->setSectorStyle($perlchartdir::RoundedEdgeShading, 0xffffff, 1);
# Create the image and save it in a temporary location my
$chart2URL = $c->makeTmpFile("/tmp/tmpcharts");
# Create an image map for the chart my
$imageMap2 = $c->getHTMLImageMap("detail.pl?", "", "title='{label} : {value} : {percent}%'","");
print '
<img src="/processes/getchart.pl?img=/tmp/tmpcharts/' . $chart2URL . '" border="0" usemap="#map2">
<map name="map2">' . $imageMap2 . '</map> ';
print '</body>
</html>';
</code> |
Re: perl $c->makeTmpFile multiple charts on the same page. |
Posted by Peter Kwan on Feb-14-2013 03:14 |
|
Hi Donavon,
Sorry for my misunderstanding of your enquiry.
The method you are using is already a good method. Basically, if you have multiple charts, all with tooltips, you can just create them one by one. (Even with makeSession, the code would be similar.) If all your charts are similar, you may put the code in a subroutine so you do not have to repeat the code. One key point is that HTML requires all <map> tags to have unique names, so if one tag is called "map1", the other tag must use another name (such as "map2").
Regards
Peter Kwan |
Re: perl $c->makeTmpFile multiple charts on the same page. |
Posted by Donavon on Feb-26-2013 06:29 |
|
Thanks...
I think this solves the problem without extra programming. Let me know if there is an issue with this method. I just used the name returned by $chart1URL as the map name.
print '
<img src="/processes/getchart.pl?img=/tmp/tmpcharts/' . $chart1URL . '" border="0" usemap="#' . $chart1URL . '>
<map name="' . $chart1URL . '">' . $imageMap1 . '</map> '; |
Re: perl $c->makeTmpFile multiple charts on the same page. |
Posted by Peter Kwan on Feb-26-2013 21:49 |
|
Hi Donavon,
In the current version of ChartDirector, $chart1URL is a valid filename, and it happens to be also a valid HTML name attribute (that is, it does not contain special characters that are not valid in HTML). So your method should work.
For future versions of ChartDirector, I think it is very likely the temporary filename generated by makeTmpFile would also be a valid HTML name attribute, as we cannot think of a reason why we would use special characters in filenames.
Regards
Peter Kwan |
|