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

Message ListMessage List     Post MessagePost Message

  Bar comming from Negative value to a positive value
Posted by Omar on Apr-26-2007 09:00
Attachments:
Hi Peter, how can I draw a chart like this.

My problem is how to set the bar for comming from a Negative value to a positive value like the blue one.

Thks
Bar.jpg

  Re: Bar comming from Negative value to a positive value
Posted by Peter Kwan on Apr-26-2007 17:27
Hi Omar,

There is a sample code "Pos/Neg Waterfall Chart" which is similar to the one you attached, please it is a 2D chart. For a 3D chart, you need to emulate the chart with an overlay bar layer with transparent bar segments. The closest code I can create is as follows, however, the 3D effect only works perfectly if the top side of the floating bar is positive. (The bottom side can be both positive or negative.)

$layer = $c->addBarLayer2(Overlay);
#$layer->set3D();   #uncommet for 3D effects
$layer->setBarShape(CircleShape);
$layer->setBorderColor(Transparent);
for ($i = 0; $i < count($boxTop); ++$i)
{
    $dataTop = array_pad(array(), $i + 1, NoValue);
    $dataBottom = array_pad(array(), $i + 1, NoValue);
    $dataTop[$i] = $boxTop[$i];
    $dataBottom[$i] = $boxBottom[$i];

    if ($boxBottom[$i] >= 0)
    {
         #both top side and bottom side positive
         $layer->addDataSet($dataBottom, Transparent);
         $layer->addDataSet($dataTop, DataColor + $i);
    }
    else if ($boxTop[$i] <= 0)
    {
         #both top side and bottom side negative
         $layer->addDataSet($dataBottom, DataColor + $i);
         $layer->addDataSet($dataTop, Transparent);
    }
    else
    {
         #top is positive and bottom is negative
         $layer->addDataSet($dataTop, DataColor + $i);
         $layer->addDataSet($dataBottom, DataColor + $i);
    }
}

Hope this can help.

Regards
Peter Kwan

  Re: Bar comming from Negative value to a positive value
Posted by Omar on Jun-20-2007 22:06
Attachments:
Hi Peter...

I have tried your solution and I works like you said (negative top side values don't look perfect with 3D, but that's no the problem).

Can I have your solution "addBarLayer2(Overlay)" (overlaping 2 bar series, when values come from negative to positive) and have also normal Stacked "addBarLayer2(Stack)" (for positive values) in the same chart??

Since I can have a chart, with some series with all values positive and having also some series with negative and positive values (bars coming from negative to positive Y axis values).

I trying to get a solution for both cases.

So I try your solution and also use the normal stacked with some datasets (one for each color, and the transparent for floating). But I got this chart.

I need to get something like the second chart.

Any ideas?
BarStacked.jpg
BarStacked2.jpg

  Re: Bar comming from Negative value to a positive value
Posted by Peter Kwan on Jun-21-2007 04:43
Hi Omar,

The addBarLayer2(Overlay) method I suggest should also work for purely positive values and purely negative values. I used the following code (I just add one more data group), and it seems to produce the chart you want:

$boxTop = array(2, 6, 7, 8, -2);
$boxBottom = array(0, 3, -2, 5, -4);

$boxTop2 = array(20, 20, 60, 30, -20);
$boxBottom2 = array(0, 10, -20, 10, -40);

$layer = $c->addBarLayer2(Overlay);
$layer->set3D();
$layer->setBarShape(CircleShape);
$layer->setBorderColor(Transparent);

for ($i = 0; $i < count($boxTop); ++$i)
{
$dataTop = array_pad(array(), $i + 1, NoValue);
$dataBottom = array_pad(array(), $i + 1, NoValue);
$dataTop[$i] = $boxTop[$i];
$dataBottom[$i] = $boxBottom[$i];

if ($boxBottom[$i] >= 0)
{
     $layer->addDataSet($dataBottom, Transparent);
     $layer->addDataSet($dataTop, DataColor + $i);
}
else if ($boxTop[$i] <= 0)
{
     $layer->addDataSet($dataBottom, DataColor + $i);
     $layer->addDataSet($dataTop, Transparent);
}
else
{
     $layer->addDataSet($dataTop, DataColor + $i);
     $layer->addDataSet($dataBottom, DataColor + $i);
}
}

$layer->addDataGroup();

for ($i = 0; $i < count($boxTop2); ++$i)
{
$dataTop = array_pad(array(), $i + 1, NoValue);
$dataBottom = array_pad(array(), $i + 1, NoValue);
$dataTop[$i] = $boxTop2[$i];
$dataBottom[$i] = $boxBottom2[$i];

if ($boxBottom[$i] >= 0)
{
     $ds = $layer->addDataSet($dataBottom, Transparent);
     $ds->setUseYAxis2();
     $ds = $layer->addDataSet($dataTop, DataColor + $i + count($boxTop));
     $ds->setUseYAxis2();
}
else if ($boxTop[$i] <= 0)
{
     $ds = $layer->addDataSet($dataBottom, DataColor + $i + count($boxTop));
     $ds->setUseYAxis2();
     $ds = $layer->addDataSet($dataTop, Transparent);
     $ds->setUseYAxis2();
}
else
{
     $ds = $layer->addDataSet($dataTop, DataColor + $i + count($boxTop));
     $ds->setUseYAxis2();
     $ds = $layer->addDataSet($dataBottom, DataColor + $i + count($boxTop));
     $ds->setUseYAxis2();
}
}

Hope this can help.

Regards
Peter Kwan

  Re: Bar comming from Negative value to a positive value
Posted by Omar on Dec-18-2007 06:03
Attachments:
Hi Peter,

Our Quality team reports the fact that FloatCharts don't look perfect if the top side of the floating bar is negative, as you said before.

Is there anyway to solve this problem, any idea please?

Thanks
barInc.JPG

  Re: Bar comming from Negative value to a positive value
Posted by Peter Kwan on Dec-18-2007 11:06
Hi Omar,

I have not tested the following method, but I think it should work.

(A) Add a large enough value to all your data values. For example, add 200000000000 to your data that uses the left y-axis, and add 100 to the data to that uses the right y-axis. Now all data values are positive, so your chart looks correct.

(b) Configure the y-axis label to show the label as 200000000000 less than the actual value. For example:

$c->yAxis->setLabelFormat("{={value|~.}-200000000000}");

Also, for the right y-axis:

$c->yAxis->setLabelFormat("{={value|~.}-100}");

Hope this can help.

Regards
Peter Kwan

  Re: Bar comming from Negative value to a positive value
Posted by Omar Arteaga on Feb-29-2012 01:18
Attachments:
Hi Peter,

I reply in this thread because the issue is in this type of chart.

Currently I used Layer.setBorderColor for get Shading Effects in this type of chart (I already used in stacked chart, single charts, etc) but when I set the setBorderColor also appears the border of the Dataset that used to be hidden (transparent) because setBorderColor affect all data sets.

So I try to use DataSet.setDataColor, in the Dataset that is transparent to try to hide the border with not results.

I send you a picture of the problem.

Any Idea?

How to hide the borders of the Transparent DataSet and preserve the shading effects in the others ones?

Thanks
setBorderColor.JPG

  Re: Bar comming from Negative value to a positive value
Posted by Peter Kwan on Feb-29-2012 23:28
Hi Omar,

For your case, if you are using 2D bar charts without stacked bar or "bar grouping", you may consider to use a box-whisker layer instead. The box in the box-whisker layer also supports "glass effect" and "soft lighting effect". Also, the code for a box-whisker layer may be simplier than a stacked bar layer.

However, the box-whisker layer does not support the "bar lighting" effect. This effect can be achieved with the stacked bar layer as this effect does not have the "glare" for transparent bars. If this effect needs to be supported, you may need to check which effect is used, and switch to the box-whisker layer or stacked bar layer.

In "pseudo code", it may be like:

Layer layer;
if (.... use bar lighting ....) {
    layer = c.addBarLayer(Chart.Stack);
    layer.setBorderColor(Chart.Transparent, Chart.barLighting(0.75, 2.0));
    layer.addDataSet(........);
    ............
} else {
    layer = c.addBoxWhiskerLayer2(boxTop, boxBottom, null, null, null, colorsArray);
    layer.setBorderColor(Chart.Transparent, Chart.softLighting(cd.Top));
}

You may refer to the sample code "Waterfall Chart" for an example of how to use the box-whisker layer to create floating boxes.

Hope this can help.

Regards
Peter Kwan

  Re: Bar comming from Negative value to a positive value
Posted by Omar Arteaga on Mar-01-2012 00:32
Hi Peter,

Both support 2D/3D bars are required in this chart (user can select an option). For that reason I use bar stacked charts.

If glass and soft effects can't be used because the glare on the transparent bars I will allow only bar lighting effect to active on the chart (users can configure the chart using a wizard), but I prefer to ask you first since you have always give a solution.

Thanks

  Re: Bar comming from Negative value to a positive value
Posted by Peter Kwan on Mar-02-2012 00:59
Hi Omar,

I have not tried myself, but I think you can add glass and soft effects by using an additional box-whisker layer. In this method, the bar itself has no effect.

    layer = c.addBarLayer(Chart.Stack);
    layer.addDataSet(........);
    ............

if (.... use bar lighting ....) {
    //lighting effect is on the bar
    layer.setBorderColor(Chart.Transparent, Chart.barLighting(0.75, 2.0));
} else {
    //use another layer for the effect
    layer.setBorderColor(Chart.Transparent);
    BoxWhiskerLayer layer2 = c.addBoxWhiskerLayer2(boxTop, boxBottom, null, null, null, colorsArray);
    layer2.setBorderColor(Chart.Transparent, Chart.softLighting(cd.Top));
    layer2.setDataGap(0.25);
    layer2.moveFront(layer);
}

Regards
Peter Kwan