#!/usr/local/bin/perl -w use strict; use lib '../.'; use Tk; use Tk::Graph; use Date::Format; use PostScript::Convert qw/psconvert/; my $mw = Tk::MainWindow->new; my $data = { 'one' => 0.1, 'two' => 0.1, 'three' => 10, }; my $ca = $mw->Graph( -type => 'HBARS', # -shadowdepth => 5, -padding => [50,50,50,50], -light => [80,50,0], -wire => 'gray', -bg => 'white', -threed => 10, )->pack(-expand => 1, -fill => 'both'); $ca->set($data); # Auf Daten anzeigen my $export_button = $mw->Button( -command => sub{ btn_export_canvas($mw, $ca) }, -text => 'export canvas', )->pack(); Tk::MainLoop; =head2 btn_export_canvas( $mw, $graph ) todo =cut sub btn_export_canvas { my $mw = shift; my $graph = shift; # -- file dialog my $types = [ ['PNG files', '.png'], ['All Files', '*'],]; my $output_path = $mw->getSaveFile( -filetypes => $types, -initialfile => time2str("%Y-%m-%d", time()) . '-export', -defaultextension => '.png', ); return 0 unless $output_path; # -- actual export my @all_items = $graph->find('all'); my @bbox = $graph->bbox(@all_items); my $ps = $graph->postscript( '-x' => $bbox[0], '-y' => $bbox[1], -width => $bbox[2] - $bbox[0], -height => $bbox[3] - $bbox[1], ); psconvert(\$ps, $output_path, format => 'png'); return 1; } # /btn_export_canvas