Styles > How to Use |
To use the Styles feature in FusionCharts, you first need to define your styles in the XML data document. To define styles, the following XML is used: |
|
<graph> <!-- Your data here --> <styles> |
As you can see above, all the style related elements and attributes appear under the <styles> parent element. It should effectively contain all your style related XML code. FusionCharts will not recognize any style definition outside the <styles> parent element. |
Children to <styles> element are <definition> and <application> elements. As the name suggests, <definition> element contains your custom styles definition for the chart while under <application> element you apply your custom defined styles to different chart objects. |
Now, let's first get to the definition of styles. |
Defining your Styles |
Cruising back through the above XML code, you'll see that we've defined three custom styles namely:
|
Each style has to be defined using the <style> element. Multiple style elements may be placed one after another under <definition> element. So, if you wish to define five custom styles, you need to create five <style> elements. |
Depending on the style type you are defining, each <style> element can have multiple attributes. In the above code example, each <style> element has its own set of properties. However, following two attributes are common to all:
|
Both the attributes are mandatory for each style definition. |
Mandatory Attributes |
Style Name |
Name attribute lets you assign your custom name for the style definition. For example, in the above code, we have named the font style as MyFirstFontStyle, which could well have been JohnFirstStyle or GlobalFont or BigFont etc. |
Format: name='stylename' |
Example: |
There are no restrictions on the style name, barring the pointers below:
|
Style Type |
Each style needs to be defined as to what type it is. The type defines what this style is going to do. FusionCharts v3 supports six style types:
|
So, the type attribute expects one of the above six values as its parameter. In our example, we've defined the first style type as "font", second one as "animation" and third one as "shadow", which is self explanatory. |
Format: type='parameter' (must be either 'Font' or 'Animation' or 'Shadow' or 'Glow' or 'Blur' or 'Bevel') |
|
Example: |
If you do not define a style type for a particular style, FusionCharts will ignore the style definition and log an error in the Debug Window. |
|
Other Attributes |
The rest of the attributes for a style element are dependent on its Type. For example, we can use face, size, color, bold etc. property for a FONT style type. However, the same is not valid for ANIMATION style type, as these parameters make no sense for an animation. Each style type has therefore its own set of attributes which you can specify which will be discussed next. Now, if you're already eager to apply the styles to chart objects, let's get to the application part of the story. |
Applying custom defined styles to chart objects |
To apply your defined styles to chart objects, you first need to make sure that you've the list of chart objects. This can be found in the "XML Sheet" for each chart. Each chart has a different list of Objects. So, you need to ensure that you're working with the right Object name for the given chart. Now, the following XML does the work of applying styles to different chart objects: |
<application> |
Each <apply> element helps to apply multiple styles to one chart object e.g., in our code, we first apply the MyFirstFontStyle font style to Caption of the chart and then apply the shadow style MyFirstShadow to the same object. To apply multiple styles, we separate the names of the respective styles by a comma. |
Format: <apply toObject='Object' styles='Style1, Style2, Style3 ...' /> |
You need to make sure of few things here: |
|
|
And now that you're familiar with style definition and application, we move on to see the list of parameters supported by each style type. We start with FONT style next. |