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

Message ListMessage List     Post MessagePost Message

  low value bars missing
Posted by Vesna Groba on Feb-27-2012 23:48
We have a problem displaying low values in bar (and stacked bar) charts. The code below does not display the "1" bar from the end of the data array at all.
Resizing the graph (e.g. $c = new XYChart(600, 600);$c->setPlotArea(30, 20, 500, 500)) helps, but is of course not a solution.

Any remedy to this? Many thanks for the help in advance,

BR

Vesna

**********************************************************
# The data for the bar chart
$data = array(69,212,587,318,161,102,70,38,35,19,15,12,4,4,9,8,3,2,0,0,1,0,0,0,0,0,0,0,0);

$c = new XYChart(300, 600);
$c->setPlotArea(30, 20, 200, 500);
$c->swapXY(true);

# Add a bar chart layer using the given data
$c->addBarLayer($data);

# Set the labels on the x axis.
$c->xAxis->setLabels($labels);

# Output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));

  Re: low value bars missing
Posted by Peter Kwan on Feb-28-2012 06:32
Hi Vesna,

ChartDirector will accurately draw a bar according to its data value. However, if the bar turns out to be shorter than 1 pixel, it may not be visible on the chart. (If there is a bar with value 0.000000000000000001, and we artificial make it 1-pixel height to to it visible, then it will become indistinguishable with another bar with value 3 for your case. So this behaviour is not built into ChartDirector.)

For your case, there are several methods:

(a) Use Log Scale ($c->yAxis->setLogScale();). Because a log scale has a much wider range, so all bars should be visible. However, the data should not contain 0 in log scale (as the logarithm of 0 is undefined). They should be replaced with NoValue.

(b) Put a label at the right side of the bar to show its value. ($layer = $c->addBarLayer($data); $layer->setAggregateLabelStyle();) This works if the bar is high enough for a label. If the bars are very dense, there may not be enough space for labels.

(c) Use another layer to put another symbol on the chart, of which the symbol size is not dependent on the data value (so it is visible even if the data value is 0). For example, the "whisker line" from the box-whisker layer can be used:

$layer = $c->addBoxWhiskerLayer(null, null, null, null, $data, 0xff0000, 0xff0000);
$layer->setLineWidth(2);
$layer->setDataGap(0.3);

Hope this can help.

Regards
Peter Kwan

  Re: low value bars missing
Posted by Vesna Groba on Feb-28-2012 17:58
Hi Peter,

many thanks for you thoughts. Unfortunately none of them really worked. Essentially with the low values it does not really matter whether they are completely accurately depicted (e.g. 1 or 3, compared to a couple of hundred), yet an indication that something is there is a must.

Since we are outputting svg charts, then transforming them to pdfs, our solution is to produce a larger chart than needed (2x, 4x) and then scale it down at the time of pdf transformation. This way the low values are depicted and the result is visually still rather pleasing.

Best regards and thanks again,

Vesna