{
    "mode": "perldoc",
    "parameter": "Spreadsheet::WriteExcel::Chart::Stock",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Spreadsheet%3A%3AWriteExcel%3A%3AChart%3A%3AStock/json",
    "generated": "2026-06-13T20:08:45Z",
    "synopsis": "To create a simple Excel file with a Stock chart using Spreadsheet::WriteExcel:\n#!/usr/bin/perl -w\nuse strict;\nuse Spreadsheet::WriteExcel;\nmy $workbook  = Spreadsheet::WriteExcel->new( 'chart.xls' );\nmy $worksheet = $workbook->addworksheet();\nmy $chart     = $workbook->addchart( type => 'stock' );\n# Add a series for each Open-High-Low-Close.\n$chart->addseries( categories => '=Sheet1!$A$2:$A$6', values => '=Sheet1!$B$2:$B$6' );\n$chart->addseries( categories => '=Sheet1!$A$2:$A$6', values => '=Sheet1!$C$2:$C$6' );\n$chart->addseries( categories => '=Sheet1!$A$2:$A$6', values => '=Sheet1!$D$2:$D$6' );\n$chart->addseries( categories => '=Sheet1!$A$2:$A$6', values => '=Sheet1!$E$2:$E$6' );\n# Add the worksheet data the chart refers to.\n# ... See the full example below.\nEND",
    "sections": {
        "NAME": {
            "content": "Stock - A writer class for Excel Stock charts.\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "To create a simple Excel file with a Stock chart using Spreadsheet::WriteExcel:\n\n#!/usr/bin/perl -w\n\nuse strict;\nuse Spreadsheet::WriteExcel;\n\nmy $workbook  = Spreadsheet::WriteExcel->new( 'chart.xls' );\nmy $worksheet = $workbook->addworksheet();\n\nmy $chart     = $workbook->addchart( type => 'stock' );\n\n# Add a series for each Open-High-Low-Close.\n$chart->addseries( categories => '=Sheet1!$A$2:$A$6', values => '=Sheet1!$B$2:$B$6' );\n$chart->addseries( categories => '=Sheet1!$A$2:$A$6', values => '=Sheet1!$C$2:$C$6' );\n$chart->addseries( categories => '=Sheet1!$A$2:$A$6', values => '=Sheet1!$D$2:$D$6' );\n$chart->addseries( categories => '=Sheet1!$A$2:$A$6', values => '=Sheet1!$E$2:$E$6' );\n\n# Add the worksheet data the chart refers to.\n# ... See the full example below.\n\nEND\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module implements Stock charts for Spreadsheet::WriteExcel. The chart object is created via\nthe Workbook \"addchart()\" method:\n\nmy $chart = $workbook->addchart( type => 'stock' );\n\nOnce the object is created it can be configured via the following methods that are common to all\nchart classes:\n\n$chart->addseries();\n$chart->setxaxis();\n$chart->setyaxis();\n$chart->settitle();\n\nThese methods are explained in detail in Spreadsheet::WriteExcel::Chart. Class specific methods\nor settings, if any, are explained below.\n",
            "subsections": []
        },
        "Stock Chart Methods": {
            "content": "There aren't currently any stock chart specific methods. See the TODO section of\nSpreadsheet::WriteExcel::Chart.\n\nThe default Stock chart is an Open-High-Low-Close chart. A series must be added for each of\nthese data sources.\n\nThe default Stock chart is in black and white. User defined colours will be added at a later\nstage.\n",
            "subsections": []
        },
        "EXAMPLE": {
            "content": "Here is a complete example that demonstrates most of the available features when creating a\nStock chart.\n\n#!/usr/bin/perl -w\n\nuse strict;\nuse Spreadsheet::WriteExcel;\n\nmy $workbook    = Spreadsheet::WriteExcel->new( 'chartstockex.xls' );\nmy $worksheet   = $workbook->addworksheet();\nmy $bold        = $workbook->addformat( bold => 1 );\nmy $dateformat = $workbook->addformat( numformat => 'dd/mm/yyyy' );\n\n# Add the worksheet data that the charts will refer to.\nmy $headings = [ 'Date', 'Open', 'High', 'Low', 'Close' ];\nmy @data = (\n[ '2009-08-23', 110.75, 113.48, 109.05, 109.40 ],\n[ '2009-08-24', 111.24, 111.60, 103.57, 104.87 ],\n[ '2009-08-25', 104.96, 108.00, 103.88, 106.00 ],\n[ '2009-08-26', 104.95, 107.95, 104.66, 107.91 ],\n[ '2009-08-27', 108.10, 108.62, 105.69, 106.15 ],\n);\n\n$worksheet->write( 'A1', $headings, $bold );\n\nmy $row = 1;\nfor my $data ( @data ) {\n$worksheet->write( $row, 0, $data->[0], $dateformat );\n$worksheet->write( $row, 1, $data->[1] );\n$worksheet->write( $row, 2, $data->[2] );\n$worksheet->write( $row, 3, $data->[3] );\n$worksheet->write( $row, 4, $data->[4] );\n$row++;\n}\n\n# Create a new chart object. In this case an embedded chart.\nmy $chart = $workbook->addchart( type => 'stock', embedded => 1 );\n\n# Add a series for each of the Open-High-Low-Close columns.\n$chart->addseries(\ncategories => '=Sheet1!$A$2:$A$6',\nvalues     => '=Sheet1!$B$2:$B$6',\nname       => 'Open',\n);\n\n$chart->addseries(\ncategories => '=Sheet1!$A$2:$A$6',\nvalues     => '=Sheet1!$C$2:$C$6',\nname       => 'High',\n);\n\n$chart->addseries(\ncategories => '=Sheet1!$A$2:$A$6',\nvalues     => '=Sheet1!$D$2:$D$6',\nname       => 'Low',\n);\n\n$chart->addseries(\ncategories => '=Sheet1!$A$2:$A$6',\nvalues     => '=Sheet1!$E$2:$E$6',\nname       => 'Close',\n);\n\n# Add a chart title and some axis labels.\n$chart->settitle( name => 'Open-High-Low-Close', );\n$chart->setxaxis( name => 'Date', );\n$chart->setyaxis( name => 'Share price', );\n\n# Insert the chart into the worksheet (with an offset).\n$worksheet->insertchart( 'F2', $chart, 25, 10 );\n\nEND\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "John McNamara jmcnamara@cpan.org\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright MM-MMX, John McNamara.\n\nAll Rights Reserved. This module is free software. It may be used, redistributed and/or modified\nunder the same terms as Perl itself.\n",
            "subsections": []
        }
    },
    "summary": "Stock - A writer class for Excel Stock charts.",
    "flags": [],
    "examples": [
        "Here is a complete example that demonstrates most of the available features when creating a",
        "Stock chart.",
        "#!/usr/bin/perl -w",
        "use strict;",
        "use Spreadsheet::WriteExcel;",
        "my $workbook    = Spreadsheet::WriteExcel->new( 'chartstockex.xls' );",
        "my $worksheet   = $workbook->addworksheet();",
        "my $bold        = $workbook->addformat( bold => 1 );",
        "my $dateformat = $workbook->addformat( numformat => 'dd/mm/yyyy' );",
        "# Add the worksheet data that the charts will refer to.",
        "my $headings = [ 'Date', 'Open', 'High', 'Low', 'Close' ];",
        "my @data = (",
        "[ '2009-08-23', 110.75, 113.48, 109.05, 109.40 ],",
        "[ '2009-08-24', 111.24, 111.60, 103.57, 104.87 ],",
        "[ '2009-08-25', 104.96, 108.00, 103.88, 106.00 ],",
        "[ '2009-08-26', 104.95, 107.95, 104.66, 107.91 ],",
        "[ '2009-08-27', 108.10, 108.62, 105.69, 106.15 ],",
        ");",
        "$worksheet->write( 'A1', $headings, $bold );",
        "my $row = 1;",
        "for my $data ( @data ) {",
        "$worksheet->write( $row, 0, $data->[0], $dateformat );",
        "$worksheet->write( $row, 1, $data->[1] );",
        "$worksheet->write( $row, 2, $data->[2] );",
        "$worksheet->write( $row, 3, $data->[3] );",
        "$worksheet->write( $row, 4, $data->[4] );",
        "$row++;",
        "# Create a new chart object. In this case an embedded chart.",
        "my $chart = $workbook->addchart( type => 'stock', embedded => 1 );",
        "# Add a series for each of the Open-High-Low-Close columns.",
        "$chart->addseries(",
        "categories => '=Sheet1!$A$2:$A$6',",
        "values     => '=Sheet1!$B$2:$B$6',",
        "name       => 'Open',",
        ");",
        "$chart->addseries(",
        "categories => '=Sheet1!$A$2:$A$6',",
        "values     => '=Sheet1!$C$2:$C$6',",
        "name       => 'High',",
        ");",
        "$chart->addseries(",
        "categories => '=Sheet1!$A$2:$A$6',",
        "values     => '=Sheet1!$D$2:$D$6',",
        "name       => 'Low',",
        ");",
        "$chart->addseries(",
        "categories => '=Sheet1!$A$2:$A$6',",
        "values     => '=Sheet1!$E$2:$E$6',",
        "name       => 'Close',",
        ");",
        "# Add a chart title and some axis labels.",
        "$chart->settitle( name => 'Open-High-Low-Close', );",
        "$chart->setxaxis( name => 'Date', );",
        "$chart->setyaxis( name => 'Share price', );",
        "# Insert the chart into the worksheet (with an offset).",
        "$worksheet->insertchart( 'F2', $chart, 25, 10 );",
        "END"
    ],
    "see_also": []
}