SVG::TT::Graph::Bubble(3pm) | User Contributed Perl Documentation | SVG::TT::Graph::Bubble(3pm) |
SVG::TT::Graph::Bubble - Create presentation quality SVG Bubble plot
use SVG::TT::Graph::Bubble;
my @data = ( 2, 15, 18.10, 6, 19, 0.10, 12, 17, 12.92, 17, 10, 17.97 );
my $graph =
SVG::TT::Graph::Bubble->new( { 'height' => '500',
'width' => '300',
} );
$graph->add_data( { 'data' =>
\@data_cpu,
'title' => 'CPU',
} );
print "Content-type: image/svg+xml\n\n"; print $graph->burn();
This object aims to allow you to easily create high quality SVG Bubble plot graphs using xyz data. You can either use the default style sheet or supply your own. Either way there are many options which can be configured to give you control over how the graph is generated - with or without a key, data elements at each point, title, subtitle etc.
use SVG::TT::Graph::Bubble; my $graph = SVG::TT::Graph::Bubble->new({ # Optional - defaults shown 'height' => 500, 'width' => 300, 'show_y_labels' => 1, 'yscale_divisions' => '', 'min_yscale_value' => 0, 'max_yscale_value' => '', 'show_x_labels' => 1, 'xscale_divisions' => '', 'min_xscale_value' => '', 'max_xscale_value' => '', 'stagger_x_labels' => 0, 'rotate_x_labels' => 0, 'y_label_formatter' => sub { return @_ }, 'x_label_formatter' => sub { return @_ }, 'show_data_values' => 1, 'rollover_values' => 0, 'area_fill' => 0, 'show_x_title' => 0, 'x_title' => 'X Field names', 'show_y_title' => 0, 'y_title' => 'Y Scale', 'show_graph_title' => 0, 'graph_title' => 'Graph Title', 'show_graph_subtitle' => 0, 'graph_subtitle' => 'Graph Sub Title', 'key' => 0, 'key_position' => 'right', # Stylesheet defaults 'style_sheet' => '/includes/graph.css', # internal stylesheet 'random_colors' => 0, 'bubble_fill' => 0.4, 'bubble_border_stroke' => 0, });
The constructor takes a hash reference with values defaulted to those shown above - with the exception of style_sheet which defaults to using the internal style sheet.
my @data = ( 2, 15, 18.10, 6, 19, 0.10, 12, 17, 12.92, 17, 10, 17.97 ); or my @data = ( [2, 15, 18.10] , [6, 19, 0.10], [12, 17, 12.92], [17, 10, 17.97], ); or my @data = ( { x => 2, y => 15, z => 18.10 }, { x => 6, y => 19, z => 0.10 }, { x => 12, y => 17, z => 12.92 }, { x => 17, y => 10, z => 17.97 }, ) $graph->add_data({ 'data' => \@data_cpu, 'title' => 'CPU', });
This method allows you to add data to the graph object. The data are expected to be either a list of scalars (in which case pairs of elements are taken to be X,Y pairs) or a list of array references. In the latter case, the first two elements in each referenced array are taken to be X and Y, and the optional third element (if present) is used as the text to display for that point for show_data_values and rollover_values; otherwise the Y value itself is displayed. It can be called several times to add more data sets in.
my $graph->clear_data();
This method removes all data from the object so that you can reuse it to create a new graph but with the same config options.
print $graph->burn();
This method processes the template with the data and config which has been set and returns the resulting SVG.
This method will croak unless at least one data set has been added to the graph object.
my $value = $graph->method(); my $confirmed_new_value = $graph->method($value);
The following is a list of the methods which are available to change the config of the graph object after it has been created.
Set to "inline:<style>...</style>" with your CSS in between the tags. You can thus override the default style without requireing an external URL.
The default stylesheet handles up to 12 data sets. All data series over the 12th will have no style and be in black. If you have over 12 data sets you can assign them all random colors (see the random_color() method) or create your own stylesheet and add the additional settings for the extra data sets.
To create an external stylesheet create a graph using the default internal version and copy the stylesheet section to an external file and edit from there.
$graph->x_label_formatter( sub { return '$' . $_[0] } );
$graph->y_label_formatter( sub { return '$' . $_[0] } );
For examples look at the project home page http://leo.cuckoo.org/projects/SVG-TT-Graph/
None by default.
SVG::TT::Graph, SVG::TT::Graph::Line, SVG::TT::Graph::Bar, SVG::TT::Graph::BarHorizontal, SVG::TT::Graph::BarLine, SVG::TT::Graph::Pie, Compress::Zlib, XML::Tidy
2022-11-19 | perl v5.36.0 |