ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Dual axis line chart with different line widths
Posted by Steve on Sep-04-2021 07:14
I am trying to create a dual axis line chart in Perl with one line thicker than the other. I am not sure how to reference the line layer to change its width once I have bound it to the second axis.  Here is the code:

sub writegraph{
    my ($mfd,$labels,$data0,$data1) =  @_;
    # Create a XYChart object of size 300 x 180 pixels
    my $c = new XYChart(800, 600);

    # Set the plot area at (50, 20) and of size 200 x 130 pixels
    $c->setPlotArea(50, 20, 700, 510);

    # Add a title to the chart using 8pt Arial Bold font
    $c->addTitle("Moral Foundation $mfd", "Arial Bold", 12);

    # Set the labels on the x axis.

    my $tb = $c->xAxis()->setLabels($labels);
    $tb->setFontAngle(90);

    # Add a title to the primary (left) y axis
    $c->yAxis()->setTitle("Avg Sentiment");

    # Set the axis, label and title colors for the primary y axis to red (0xc00000) to match the first
    # data set
    $c->yAxis()->setColors(0x808080, 0x808080, 0x808080);

    # Add a title to the secondary (right) y axis
    $c->yAxis2()->setTitle("Avg Probability");

    # set the axis, label and title colors for the primary y axis to green (0x008000) to match the
    # second data set
    $c->yAxis2()->setColors(0x000000, 0x000000, 0x000000);

    # Add a line layer to for the first data set using grey (0xc808080) color with a line width to 3
    # pixels
    $c->addLineLayer($data0, 0x808080)->setLineWidth(1);

    # Add a bar layer to for the second data set using black (0x000000) color. Bind the second data set
    # to the secondary (right) y axis
    $c->addLineLayer($data1, 0x000000)->setUseYAxis2();
    # how to set the width of the line layer for $data1 here?

    # Output the chart
    $c->makeChart("$mfd-summary.png");
}

  Re: Dual axis line chart with different line widths
Posted by Peter Kwan on Sep-04-2021 16:55
Hi Steve,

Instead of:

$c->addLineLayer($data1, 0x000000)->setUseYAxis2();

please use:

$myLineLayer = $c->addLineLayer($data1, 0x000000);
$myLineLayer->setUseYAxis2();
$myLineLayer->setLineWidth(3);

Hope this can help.

Regards
Peter Kwan