use Win32::OLE qw( with in ); use Win32::OLE::Const "Microsoft Graph 9.0 Object Library"; #Win32::OLE->Uninitialize(); #Win32::OLE->Initialize( Win32::OLE::COINIT_OLEINITIALIZE ); #Win32::OLE->Initialize( Win32::OLE::COINIT_APARTMENTTHREADED ); my $TIME = time(); my $WIDTH = 640; my $HEIGHT = 400; my ( @CELLS ) = ( 'a'..'zz' ); my $File = "c:\\temp\\test.gif"; srand( time() ); $Class = "MSGraph.Application"; $Chart = new Win32::OLE( $Class ) || die "GO Away. Can not create '$Class'\n"; $Chart->{Visible} = 1; $Data = $Chart->DataSheet(); $Graph = $Chart->Chart(); $Graph->{Width} = $WIDTH; $Graph->{Height} = $HEIGHT; $Graph->{HasLegend} = 0; $Graph->{Type} = xlLine; # Align the chart so it starts on the origin $Graph->ChartGroups(1)->{HasUpDownBars} = 1 ; $Graph->ChartGroups(1)->{HasUpDownBars} = 0; # Add data to the graph foreach $Value ( 0..33 ) { my $Date = localtime( $TIME + 3600 * $Value ); $Data->Range( "$CELLS[$Value]0" )->{Value} = $Date; $Data->Range( "$CELLS[$Value]1" )->{Value} = rand( 50 ); } # Config the x-axis if( $Axis = $Graph->Axes( xlCategory ) ) { $Axis->{HasMajorGridlines} = 0; $Axis->{TickLabels}->{orientation} = xlUpward; with( $Axis->{TickLabels}->{Font}, Name => "Tahoma", Bold => 0, Italic => 0 ); } # Config the y-axis if( $Axis = $Graph->Axes( xlValue ) ) { $Axis->{HasMajorGridlines} = 1; $Axis->{MajorGridlines}->{Border}->{Weight} = 1; # The color index 48 == 40% gray $Axis->{MajorGridlines}->{Border}->{ColorIndex} = 48; $Axis->{MajorGridlines}->{Border}->{LineStyle} = xlContinuous; with( $Graph->Axes( xlValue )->{TickLabels}->{Font}, Name => "Tahoma", Bold => 0, Italic => 0 ); } # Configure the data point labels for the series collection $Graph->SeriesCollection( 1 )->{HasDataLabels} = 1; if( $Labels = $Graph->SeriesCollection(1)->DataLabels() ) { with( $Labels, NumberFormat => "#.0", Type => xlDataLabelsShowValues ); with( $Labels->{Font}, Name => "Tahoma", Bold => 0, Italic => 0, ); } # Remove any data point labels if they are redundant foreach my $Point (in( $Graph->SeriesCollection( 1 )->Points())) { my $Text = $Point->{DataLabel}->{Text}; $Point->{MarkerStyle} = xlMarkerStyleDot; $Point->{DataLabel}->{Font}->{Background} = xlBackgroundOpaque; $Point->{HasDataLabel} = 0 if( $Text eq $PrevText ); $PrevText = $Text; } $Graph->Export( $File, "GIF", 0 ); `start $File`;