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

Message ListMessage List     Post MessagePost Message

  Single XYChart line to fill whole visable area.
Posted by Donavon Lerman on Nov-21-2018 02:54
Attachments:
Hello.

I am trying to get a single stacked bar line to fill the entire plotarea.

I used the 'percentbar.pl' example file as a base and tried to modify it as much as I could to get what I needed.

Attached are 2 pictures and the script file.
percentbar.png: is as far I was able to get with my modifications.
percentbar1.png: is an edited (in a photo editor) example, to show what I am trying to achieve.

Any suggestions or links to examples that would be helpful, are greatly appreciated.

Language: perl
Example / Demo using as base: percentbar.pl
Chart Director version: 5.1

Thank You,
~Donavon
donl@mycopanet.com
percentbar.png
percentbar1.png
chart_percentbar.pl
chart_percentbar.pl

4.28 Kb

  Re: Single XYChart line to fill whole visable area.
Posted by Peter Kwan on Nov-22-2018 00:13
Attachments:
Hi Donavon,

By default, if the y-axis is auto-scaled, ChartDirector will configure the axis scale to be a little bit larger than the maximum data value, then extend the axis if necessary to the next label position. So the bar is always shorter than the plot area.

For your case, there are two methods:

(a) Use Axis.setLinearScale to specify the axis scale to just fit your data.

(b) Use Axis.setAutoScale and Axis.setRounding to configure auto-scale to just fit the data (the scale just fits the data and there is no extension to the next label position).

I have attached an example modified from your code. It uses (b) to achieve the result.

Hope this can help.

Regards
Peter Kwan
chart_percentbar.png
chart_percentbar.pl
chart_percentbar.pl

1.28 Kb

  Re: Single XYChart line to fill whole visable area.
Posted by Donavon Lerman on Nov-22-2018 01:50
Thank you Peter.

This works.


The next question is, how do I get the hover labels to show up?

I tried adding the following but it doesn't show up.
$layer->addExtraField(['Sector #1']);  ### {field0}

  Re: Single XYChart line to fill whole visable area.
Posted by Peter Kwan on Nov-23-2018 01:38
Hi Donavon.

Please refer to the "Clickable Charts" section of the documentation on how to add tooltips to the chart objects:

https://www.advsofteng.com/doc/cdperl.htm#clickablecharts.htm


In brief, in a web page, the text content (including the tooltips) is in HTML, and the graphics content is the PNG image referenced with an <IMG> tag. That means the Perl script must produce two outputs - the PNG image, and the HTML tags for the tooltips (which are <AREA> tags). The example in the Clickable Charts section demonstrates how to do this.


For your case, the code is like:


#!/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;

# The data for the bar chart
my $data0 = [100];
my $data1 = [85];
my $data2 = [97];

my $c = new XYChart(300, 100);
$c->setPlotArea(20, 0, $c->getWidth() - 41, $c->getHeight() - 1, -1, -1,
$perlchartdir::Transparent, $perlchartdir::Transparent, $perlchartdir::Transparent);
$c->swapXY();

# Set axes to transparent
$c->xAxis()->setColors($perlchartdir::Transparent, $perlchartdir::Transparent);
$c->yAxis()->setColors($perlchartdir::Transparent, $perlchartdir::Transparent);
$c->yAxis()->setAutoScale(0, 0, 1);
$c->yAxis()->setRounding(0, 0);

my $layer = $c->addBarLayer2($perlchartdir::Stack);
$layer->addDataSet($data0, 0x66aaee);
$layer->addDataSet($data1, 0xeebb22);
$layer->addDataSet($data2, 0xcc88ff);

# Enable data label at the middle of the the bar
$layer->setDataLabelStyle()->setAlignment($perlchartdir::Center);

$layer->addExtraField(['aaa', 'bbb', 'ccc']);

# Create the image and save it in a temporary location
my $chart1URL = $c->makeTmpFile("/tmp/tmpcharts");

# Create an image map for the chart
my $imageMap = $c->getHTMLImageMap("", "", "title='{dsField0}'");

print "Content-type: text/htmlnn";
print <<EndOfHTML
<html>
<body style="margin:5px 0px 0px 5px">
<img src="getchart.pl?img=/tmp/tmpcharts/$chart1URL" border="0" usemap="#map1">
<map name="map1">
$imageMap
</map>
</body>
</html>
EndOfHTML
;


Regards
Peter Kwan

  Re: Single XYChart line to fill whole visable area.
Posted by Peter Kwan on Nov-23-2018 01:39
Hi Donavon,

Note that the code in my last message relies on the getchart.pl, which must be in the same URL directory as the running script.

Regards
Peter Kwan