ChartDirector 6.0 (Perl Edition)
Multi-Line Chart (2)
Source Code Listing
#!/usr/bin/perl # In the sample code, the ChartDirector for Perl module is assumed to be in "../lib" use File::Basename; use lib (dirname($0)."/../lib") =~ /(.*)/; use perlchartdir; # In this example, we simply use random data for the 3 data series. my $r = new RanSeries(129); my $data0 = $r->getSeries(100, 100, -15, 15); my $data1 = $r->getSeries(100, 160, -15, 15); my $data2 = $r->getSeries(100, 220, -15, 15); my $timeStamps = $r->getDateSeries(100, perlchartdir::chartTime(2014, 1, 1), 86400); # Create a XYChart object of size 600 x 400 pixels my $c = new XYChart(600, 400); # Add a title box using grey (0x555555) 20pt Arial font $c->addTitle(" Multi-Line Chart Demonstration", "arial.ttf", 20, 0x555555); # Set the plotarea at (70, 70) and of size 500 x 300 pixels, with transparent background and border # and light grey (0xcccccc) horizontal grid lines $c->setPlotArea(70, 70, 500, 300, $perlchartdir::Transparent, -1, $perlchartdir::Transparent, 0xcccccc); # Add a legend box with horizontal layout above the plot area at (70, 35). Use 12pt Arial font, # transparent background and border, and line style legend icon. my $b = $c->addLegend(70, 35, 0, "arial.ttf", 12); $b->setBackground($perlchartdir::Transparent, $perlchartdir::Transparent); $b->setLineStyleKey(); # Set axis label font to 12pt Arial $c->xAxis()->setLabelStyle("arial.ttf", 12); $c->yAxis()->setLabelStyle("arial.ttf", 12); # Set the x and y axis stems to transparent, and the x-axis tick color to grey (0xaaaaaa) $c->xAxis()->setColors($perlchartdir::Transparent, $perlchartdir::TextColor, $perlchartdir::TextColor, 0xaaaaaa); $c->yAxis()->setColors($perlchartdir::Transparent); # Set the major/minor tick lengths for the x-axis to 10 and 0. $c->xAxis()->setTickLength(10, 0); # For the automatic axis labels, set the minimum spacing to 80/40 pixels for the x/y axis. $c->xAxis()->setTickDensity(80); $c->yAxis()->setTickDensity(40); # Add a title to the y axis using dark grey (0x555555) 14pt Arial font $c->yAxis()->setTitle("Y-Axis Title Placeholder", "arial.ttf", 14, 0x555555); # Add a line layer to the chart with 3-pixel line width my $layer = $c->addLineLayer2(); $layer->setLineWidth(3); # Add 3 data series to the line layer $layer->addDataSet($data0, 0x5588cc, "Alpha"); $layer->addDataSet($data1, 0xee9944, "Beta"); $layer->addDataSet($data2, 0x99bb55, "Gamma"); # The x-coordinates for the line layer $layer->setXData($timeStamps); # Output the chart $c->makeChart("multiline2.png") |
#!/usr/bin/perl # In the sample code, the ChartDirector for Perl module is assumed to be in "../lib" use File::Basename; use lib (dirname($0)."/../lib") =~ /(.*)/; use perlchartdir; # In this example, we simply use random data for the 3 data series. my $r = new RanSeries(129); my $data0 = $r->getSeries(100, 100, -15, 15); my $data1 = $r->getSeries(100, 160, -15, 15); my $data2 = $r->getSeries(100, 220, -15, 15); my $timeStamps = $r->getDateSeries(100, perlchartdir::chartTime(2014, 1, 1), 86400); # Create a XYChart object of size 600 x 400 pixels my $c = new XYChart(600, 400); # Add a title box using grey (0x555555) 20pt Arial font $c->addTitle(" Multi-Line Chart Demonstration", "arial.ttf", 20, 0x555555); # Set the plotarea at (70, 70) and of size 500 x 300 pixels, with transparent background and border # and light grey (0xcccccc) horizontal grid lines $c->setPlotArea(70, 70, 500, 300, $perlchartdir::Transparent, -1, $perlchartdir::Transparent, 0xcccccc); # Add a legend box with horizontal layout above the plot area at (70, 35). Use 12pt Arial font, # transparent background and border, and line style legend icon. my $b = $c->addLegend(70, 35, 0, "arial.ttf", 12); $b->setBackground($perlchartdir::Transparent, $perlchartdir::Transparent); $b->setLineStyleKey(); # Set axis label font to 12pt Arial $c->xAxis()->setLabelStyle("arial.ttf", 12); $c->yAxis()->setLabelStyle("arial.ttf", 12); # Set the x and y axis stems to transparent, and the x-axis tick color to grey (0xaaaaaa) $c->xAxis()->setColors($perlchartdir::Transparent, $perlchartdir::TextColor, $perlchartdir::TextColor, 0xaaaaaa); $c->yAxis()->setColors($perlchartdir::Transparent); # Set the major/minor tick lengths for the x-axis to 10 and 0. $c->xAxis()->setTickLength(10, 0); # For the automatic axis labels, set the minimum spacing to 80/40 pixels for the x/y axis. $c->xAxis()->setTickDensity(80); $c->yAxis()->setTickDensity(40); # Add a title to the y axis using dark grey (0x555555) 14pt Arial font $c->yAxis()->setTitle("Y-Axis Title Placeholder", "arial.ttf", 14, 0x555555); # Add a line layer to the chart with 3-pixel line width my $layer = $c->addLineLayer2(); $layer->setLineWidth(3); # Add 3 data series to the line layer $layer->addDataSet($data0, 0x5588cc, "Alpha"); $layer->addDataSet($data1, 0xee9944, "Beta"); $layer->addDataSet($data2, 0x99bb55, "Gamma"); # The x-coordinates for the line layer $layer->setXData($timeStamps); # Output the chart binmode(STDOUT); print "Content-type: image/png\n\n"; print $c->makeChart2($perlchartdir::PNG); |