Posted on 2009-09-28 19:56:48-07 by dweberecu
Bar graph with multiple items per x axis unit
I am trying to utilize the SVG::TT::Graph::Bar module to create a bar graph with multiple bars per x-axis unit. Is there a way to set it up to force each bar per unit to be next to rather than stacked on top of each other? Stacked Parallel ****** ****** * * * * ****** INTO * * ****** * * * * * * * * * * * * | .......
Direct Responses: 11511 | Write a response
Posted on 2009-09-29 12:32:37-07 by molecules in response to 11508
Re: Bar graph with multiple items per x axis unit
As far as I can tell, the code isn't set up to do side-by-side bars for a single "x value". But I'm new to maintaining this module, so I welcome any of the other maintainers' comments.

Are you looking for a one-time solution or a solution that you will use repeatedly? If it is a one-time solution, we can talk about hacking the SVG file (i.e. the graph file itself). If it is more of a long-term solution, then we can talk about hacking the source itself (a little more involved, but perhaps resulting in a patch that would be useful to many others as well).

Please let us know a little more of exactly what you need and we'll see how we can help.
Direct Responses: 11512 | Write a response
Posted on 2009-09-29 14:19:18-07 by dweberecu in response to 11511
Re: Bar graph with multiple items per x axis unit
Thanks for the prompt response. This is more of a one-time use, but I would also like it to help others. The ultimate goal of the project is to generate PDFs on the fly based on data retrieved from the database. The PDFs contain charts that need to be of high quality, so I decided to use this module and then convert the SVG to an image to be returned and included in the pdf creation module. Example PDF I am doing this for Pie, Double Pie, Bar, Double Bar, Triple Bars, and 4 Bar charts, although the Pie Chart module works great as is. You will see a specific example of the 4 bar per unit in the link above. I was looking at the source code to come up with a way to add an option for "bars_per_item" in the graph configuration settings. If you guys have any advise it would be greatly appreciated. Thanks again,
Direct Responses: 11525 | Write a response
Posted on 2009-10-02 13:16:54-07 by molecules in response to 11512
Re: Bar graph with multiple items per x axis unit
Here is an example graph containing "stacked bars" or perhaps better stated "overlaid bars":
http://leo.cuckoo.org/projects/SVG-TT-Graph/examples/bar_multi.svg

If you look in that file, you will find that each set of data that corresponds to each set of stacked bars is preceded by the code:
<!-- find the lowest data value for each dataset -->


Here are lines from the SVG file representing two sets of bars (omitting many newline characters):
<!-- find the lowest data value for each dataset --> <path d="M306 280 V145 h82 V280 Z" class="fill1"/> <text x="352" y="139" class="dataPointLabel">45</text> <path d="M306 280 V211 h82 V280 Z" class="fill2"/> <text x="352" y="205" class="dataPointLabel">23</text> <!-- find the lowest data value for each dataset --> <path d="M398 280 V79 h82 V280 Z" class="fill1"/> <text x="444" y="73" class="dataPointLabel">67</text> <path d="M398 280 V52 h82 V280 Z" class="fill2"/> <text x="444" y="46" class="dataPointLabel">76</text>


By the way, lowercase commands are relative and UPPERCASE are absolute.
For the code:
<path d="M398 280 V52 h82 V280 Z" class="fill2"/>

"M398 280" moves the cursor to position 398, 280
"V52" draws from that point to the absolute vertical position 52 units from the top of the image.
"h82" draws a horizontal line 82 units long.
"V280" draws a vertical line down to the absolute vertical position 280 units from the top of the image.
"Z" returns the cursor to its starting point (i.e. 398,280), thus completing the box.
class="fill2" simply references the coloring scheme "fill2" that is defined earlier in the file.

The new algorithm we need to implement your side-by-side clusters of bars would need to provide enough space at each "x-value" for the desired number of bars. We would then divide up the space for each bar etc . . .

Is that helpful?

By the way, the code that generates the SVG is written using the Template Toolkit.

Anyway, I hope this is helpful. Feel free to ask for further clarifications, help, etc.

--Christopher (molecules)
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.