如何在GD :: Graph中使用变量设置选项?

时间:2009-09-02 06:35:09

标签: perl gd-graph

我正在使用GD::Graph::lines创建图表。对于选项集,我必须为选项编写固定值,例如x_label => "label"如下代码:

my $mygraph = GD::Graph::lines->new($x, $y);
$mygraph->set(
    x_label     => 'label1',
    y_label     => 'label2',
    title       => 'title',

    line_types  => [1, 1, 1, 1],
    line_width  => 2,
) 

是否有任何方法可以使这些选项读取变量,如$x$y是输入变量?

1 个答案:

答案 0 :(得分:1)

只需替换为这样的变量:

my $mygraph = GD::Graph::lines->new($x, $y);
$mygraph->set(
    x_label     => $label_x,
    y_label     => $label_y,
    title       => $title,

    line_types  => [1, 1, 1, 1],
    line_width  => 2,
)