我需要使用Perl中的数据创建一个图形,从MySQL数据库中提取数据。如何使用Perl将图添加到网页?
我见过GD::Graph
建议和其他方式,但我不知道如何使用它们中的任何一个,并且无法在网上找到太多。
我输入了一个GD::Graph
脚本的网页,但没有出现。我假设我必须以某种方式合并HTML来显示图形,但我不知道该怎么做。
我只是需要一个基本的线条图,所以任何简单的例子都会有很大的帮助。
这里有一个例子程序,我用的是打我不能去上班:
use GD::Graph::bars;
use GD::Graph::Data;
my $data = GD::Graph::Data->new([
["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
[ 1, 2, 5, 6, 3, 1.5, 1, 3, 4],
]) or die GD::Graph::Data->error;
my $graph = GD::Graph::bars->new;
$graph->set(
x_label => 'X Label',
y_label => 'Y label',
title => 'A Simple Bar Chart',
#y_max_value => 7,
#y_tick_number => 8,
#y_label_skip => 3,
#x_labels_vertical => 1,
#bar_spacing => 10,
#shadow_depth => 4,
#shadowclr => 'dred',
#transparent => 0,
) or die $graph->error;
$graph->plot($data) or die $graph->error;
my $file = 'bars.png';
open(my $out, '>', $file) or die "Cannot open '$file' for write: $!";
binmode $out;
print $out $graph->gd->png;
close $out;
SO不是代码写入服务。请向我们展示您尝试过并需要帮助的代码。 – stevieb
我并不是要求某人为我写信,只是帮助我指出正确的方向。 – Nicolas
您显示的一段代码会创建一个图像,并将其打印到一个文件中。如果您想将其包含在HTML页面中,则必须包含该图像。或者,您可以将此代码用作CGI脚本,而不是打开文件,只需打印到STDOUT即可。首先发送正确的'image/png'标题。在你的HTML中的脚本中使用URL''标签。 – simbabque