Using FusionCharts with JSP > Chart Transparency |
In the previous section we discussed the basics of using FusionCharts with JSP. In the current section, we will see how we can make the charts transparent. We will extend our previous example and only add a few more lines of code to make the chart transparent. |
All code discussed here is present in Download Package > Code > J2EE > BasicExample folder. |
Creating a transparent and an opaque chart |
We will build two Column 3D charts, both using the same data-source. We take the exsiting SimpleChart.jsp and Data.xml (present in Data folder) and modify these to acheive our goal. We modify SimpleChart.jsp to render two column 3D charts. Let's first have a look at the modified code for SimpleChart.jsp: ( We save the it as TransparentChart.jsp) |
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%-- This page demonstrates the ease of generating charts using FusionCharts. |
As you can see above, we did the following:
As you have noticed, we have used Data_Transparent.xml file as the dataURL source for both the charts. We did a little modificaiton to the existing Data.xml file to set the background of the chart transparent and saved it as Data_Transparent.xml. Let us have a look at the modified XML: |
<chart caption='Monthly Unit Sales' xAxisName='Month' yAxisName='Units' showValues='0' formatNumberScale='0' showBorder='1' canvasBgAlpha='0' bgAlpha='0'> <set label='Jan' value='462' /> <set label='Feb' value='857' /> <set label='Mar' value='671' /> <set label='Apr' value='494' /> <set label='May' value='761' /> <set label='Jun' value='960' /> <set label='Jul' value='629' /> <set label='Aug' value='622' /> <set label='Sep' value='376' /> <set label='Oct' value='494' /> <set label='Nov' value='761' /> <set label='Dec' value='960' /> </chart> |
This XML is identical to our previous SimpleChart.jsp example except for the bgAlpha and canvasBgAlpha attributes. bgAlpha sets the opacity of the chart's main background while canvasBgAlpha sets the opacity of the chart's 3D canvas. The attributes are set to 0 to declare full transparency. |
Please note that to set a chart transparent we need to go through two steps. First we need to set the chart in Transparent mode ( windowMode="transparent" ) . Finally, we need to set bgAlpha ( additionally canvasBgAlpha ) attribute of <chart> element to apply transparency on the chart which has been set to transparent mode. One without the other is ineffective. Hence, we would find from the above example, that even though the second chart is set with transparency attribute values it remains opaque, since it is set to opaque mode. |
The resultant charts would look as follows: |
We find that the first chart is transparent. The background has vanished and the container's purple color is seen through the chart. The second chart, since set to opaque mode, has not turned transparent. Rather, an opaque white background is being shown. |