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

Message ListMessage List     Post MessagePost Message

  Multi stack bar chart
Posted by Yamin on Jul-30-2010 08:13
Attachments:
1. Is there anyway i can set the origin of Y axis, right now it seems like it is set to 0. So like for example lets say i have 1 stack bar which has multiple segments in it. I only define the peak of each segment and Chartdirector calculates the height of each segment and draws the segment in the stack bar. But for some reason if i have peak values starting from positive to negative like this: 100, 50, -33, -483, then it draws stack bar from 100 to 56, 56 to 0 and 0 to -33 and -33 to -483. But my question is that why not it continues to draw 56 to -33 instead of creating 56 to 0 and 0 to -33? I am assuming its because of origin set to zero. Can you please explain why and solution if possible?

2. How to customize Y-Axis labels? i.e Can i provide an array of labels for Y-Axis? For bar charts of course.

3. Is there any Php linux version available for Chartdirector?
problem.jpg

  Re: Multi stack bar chart
Posted by Peter Kwan on Jul-31-2010 00:56
Hi Yamin,

1. The issue is not related to the y-axis origin but to the chart type. For a bar chart, each value will be a bar segment. For example, if you draw a bar with 1 value 137, there will be a bar from 0 - 137 (the base line 0 can be changed to other values using Barlayer.setBaseLine). If you draw a bar with 2 values, there will be 2 bar segments. If you draw a bar with 4 values, there will be 4 bar segments.

In your case, there are two methods:

(a) The chart you are trying to draw should be a "floating box chart". You may refer to the "Floating Box Chart" sample code for an example. (You may look for "Floating Box Chart" from the ChartDirector documentation index.)

(b) If you must use a bar chart, instead of using 100, 56, -33, -483, may be you only use 3 values 100, 56, -33. This will create 3 bar segments. Then you set the baseline (using BarLayer.setBaseLine) to -483, so that the bar will start from -483. Note that you would also need to set the y-axis scale to start from -483 in this case. (Because -483 is not a data value, so ChartDirector will not consider it when scaling the axis.) For example (in PHP):

$layer->setBaseLine(-483);
$c->yAxis->setLinearScale(-483, NoValue);


2. You may use Axis.setLabelFormat to configure the y-axis label formatting. You can also provide an array of labels (using Axis.setLinearScale2), but then you must also specify the axis scale, so ChartDirector can know how to spread the labels on the axis. For example:

$c->yAxis->setLinearScale2(100, -500, $anArrayOfTextStrings);

3. Yes. Please feel free to download it from our web site http://www.advsofteng.com/download.html

Hope this can help.

Regards
Peter Kwan

  Re: Multi stack bar chart
Posted by Yamin on Jul-31-2010 01:48
Attachments:
Thanks Peter,
If i set baseline to something negative (i.e -483), it draws the segment from -483, but the problem still remains for me. Because it still misses the segment from 0 to -33. However i found a solution for this. Please refer to my new image attachments to see how it looks.

Can i add/remove borderline for each segment? Because right now i am able to remove borders for whole bar, not for each segment.
problem2.JPG
problem3.JPG

  Re: Multi stack bar chart
Posted by Peter Kwan on Jul-31-2010 02:35
Hi Yamin,

Is it possible for me to see your code?

The border at y = 0 seems very thick. May be it is not from the bar. Your code may have added something other things to the chart (eg. another zero bar) that causes the border to appear.

Regards
Peter Kwan

  Re: Multi stack bar chart
Posted by Yamin on Jul-31-2010 02:44
function createBarJPG($param = null)
{
   if($param['data'])
   {
      foreach($param['data'] as $value)
      {
         # The data for the bar chart
         $data[] = $value;
      }
   }
   else
   {
      return false;
   }

   # Create a XYChart object of size 500 x 320 pixels
   $c = new XYChart(110, 600);

   # Set the plotarea
   $c->setPlotArea(30, 5, 80, 550, Transparent, 0xffffff, 0xffffff, -1, -1);

   # Add a stacked bar layer and set the layer 3D depth to 0 pixels
   $layer = $c->addBarLayer(Stack, 0);
   $layer->setBarWidth(75);
   $layer->setBorderColor(1);
   $c->yAxis->setLinearScale(-600, 200, 50, 10);

   $c->xAxis->setColors(-1);
   $c->yAxis->setColors(1);

   if($data)
   {
      $png = array("601.PNG", "606.PNG", "603.PNG", "602.PNG",  "607.PNG", "611.PNG", "612.PNG", "614.PNG", "619.PNG", "620.PNG", "660.PNG", "681.PNG", "701.PNG", "722.PNG");

      foreach($data as $key => $value)
      {
         if($value[0] < 0 && $count < 1)
         {
            if($key == 0)
            {
               $pattern = "001.PNG";
            }

            $myColor[$key] = $c->patternColor($_SERVER[DOCUMENT_ROOT] . "\\\\path\\\\images\\\\bmp\\\\".$pattern);
            $count++;
         }
         else
         {
            $myColor[$key] = $c->patternColor($_SERVER[DOCUMENT_ROOT] . "\\\\path\\\\images\\\\bmp\\\\".$png[$key]);
            $pattern = $png[$key];
         }

         $layer->addDataSet($data[$key], $myColor[$key], "Legend");
      }
   }

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

  Re: Multi stack bar chart
Posted by Peter Kwan on Jul-31-2010 14:56
Hi Yamin,

I thought you are using setBaseLine and still see the line at y = 0. If you are not using setBaseLine, please try to use setBaseLine. For example, you may try:

sort($data);
$layer->setBaseLine(array_shift($data));

for ($i = 0; $i < count($data); ++$i)
    $layer->addDataSet($data[$i]);

#print data value on the bar for debugging
$layer->setDataLabelStyle();

Please check if the above can produce what you want (except the color). Also, please check if the data values are what you expect (does it have some unexpected values, such as 0)? If the above is correct, you can then modify it to use your pattern colors.

If the above still does not work, would you mind to post the chart you get from the above code?

Regards
Peter Kwan