|
Gradient color and rounded corners |
Posted by Hildigunnur Halldorsdottir on Oct-03-2014 05:32 |
|
Hi
I am making a simple graph. I get the data from a mySql database.
It works fine like this:
First I am using data from the database:
startDate = array(chartTime(2003,$from_man, $from_dag));
$endDate = array(chartTime(2003, $to_man , $to_dag));
Then building the chart:
$c = new XYChart(340, 60, 0xFFFFFF);
$plotArea=$c->setPlotArea(10, 20, 320, 15, 0xeeeeee,0xeeeeee, 0xffffff,0xeeeeee, 0xeeeeee);
$c->swapXY();
$c->yAxis->setDateScale(chartTime(2003, 1, 1), chartTime(2004, 1, 1), 86400 * 30);
$c->yAxis->setLabelFormat("{value|mmm}");
$c->setMonthNames(Array("J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"));
$c->yAxis->setLabelStyle("arial.ttf", 8, 0x959595);
$c->xAxis->setTickLength(0);
$c->yAxis->setColors(0x959595);
$wiskerLayer=$c->addBoxWhiskerLayer($startDate, $endDate, null, null, null, 0xff6936,0xff6936,0xff6936);
etc
But I wanted to have the plotArea in gradient color and also the BoxWiskerLayer. I added:
$wiskerLayer->setBorderColor(Transparent, softLighting(Left));
and also
$plotArea->setBorderColor(Transparent, softLighting(Left));
Then the chart does not show up at all. What am I doing wrong?
I would also like the plotArea to have rounded corners. Is that possible?
Thanks in advance
Hildigunnur Halldorsdottir |
Re: Gradient color and rounded corners |
Posted by Peter Kwan on Oct-04-2014 02:22 |
|
Hi Hildigunnur,
According to the ChartDirector documentation, the setBorderColor is not a method of the
PlotArea object, so $plotArea->setBorderColor(....); should fail with an error message,
which show the error.
If you see a blank page instead of the error message, it is probably because your PHP is
configured not to display error messages (may be to avoid end users to accidentially see
the error message, and some people consider displaying error messages to be a security
risk). However, if the server is for development usage, it is useful to enable error
messages so you can know what is the error. You may consider to enable error_reporting
and display_errors in your PHP configuration file. See:
http://php.net/manual/en/errorfunc.configuration.php
Note that the "softLighting" is not simply a gradient color. It is a special effect applicable
only to bars and to the box in the box-whisker layer. See:
http://www.advsofteng.com/doc/cdphp.htm#Layer.setBorderColor.htm
There are several examples in ChartDirector with the plot area background in gradient
colors. For example, see the "Symbol Line Chart (2)" sample code. You can use them as a
reference.
http://www.advsofteng.com/doc/cdphp.htm#symbolline2.htm
In brief, the code is something like:
$c->setPlotArea(10, 20, 320, 15, $c->linearGradientColor(10, 0, 320, 0, 0xf9fcff,
0xaaccff), -1, Transparent, 0xffffff);
The built-in plot area cannot have rounded corners, because the axes are straight lines
docked to the plot area border, and so the plot area border must be straight.
I can think of a method to create an effect that looks like a plot area with rounded
corners. In brief, it is as follows:
(a) Use Axis.setMargin to reserve some margin on the end points of the axis which would
not have axis scale. We need to reserve this margin because the rounded part of the plot
area cannot have axis scale.
(b) Use Axis.setColors to set the axis stem color (which is a straight line) to Transparent.
(c) Set the edge and fill color of the plot area to transparent.
(d) Use BaseChart.addText to add an empty text box at the top-left corner of the plot
area, then use the Box.setSize to set the text box size as the same size of the plot area,
then use Box.setBackground to set the background and border color of the text box (you
can use a gradient color if you like), then use Box.setRoundedCorners to set rounded
corners, then use Box.setZOrder to set the border to be at the plot area background.
Hope this can help.
Regards
Peter Kwan |
|