How to Use Styles
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:
<chart> <!-- Your data here --> <styles> <definition> <style name='MyFirstFontStyle' type='font' face='Verdana' size='12' color='FF0000' bold='1' bgColor='FFFFDD' /> <style name='MyFirstAnimationStyle' type='animation' param='_xScale' start='0' duration='2' /> <style name='MyFirstShadow' type='Shadow' color='CCCCCC' /> </definition> <application> <apply toObject='Caption' styles='MyFirstFontStyle,MyFirstShadow' /> <apply toObject='Canvas' styles='MyFirstAnimationStyle' /> <apply toObject='DataPlot' styles='MyFirstShadow' /> </application> </styles> </chart>
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: MyFirstFontStyle, which will later help us in setting font properties for text on the chart. MyFirstAnimationStyle, which will help us in animating a chart object, and MyFirstShadow that can render a shadow effect on any chart object. 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: name type. 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: <style name='MyFirstFontStyle' type='font' face='Verdana' …/> <style name='MyFirstAnimationStyle' type='animation' …/> <style name='MyFirstShadow' type='Shadow' …/>
There are no restrictions on the style name, barring the pointers below: Style name can only include alphabets and numbers. Punctuation marks (including underscore) shouldn't be used. Style name must be unique, i.e., two style definitions cannot have the same name as there will be a conflict between the two.
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: Font Animation Shadow Glow Blur Bevel 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: <style name='MyFirstFontStyle' type='font' face='Verdana' …/> <style name='MyFirstAnimationStyle' type='animation' …/> <style name='MyFirstShadow' type='Shadow' …/>
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 present in each chart. This can be found here in the "Chart XML Sheet" for each chart. For example, we've the following chart objects for 2D Single Series Column Chart:
Object Name | Description | Features Supported | Animation Parameters Supported
BACKGROUND | BACKGROUND refers to the entire background of the chart. | Animation Shadow Glow Bevel Blur | _alpha _x _y _xScale _yScale
CANVAS | In 2D Charts, CANVAS refers to the area in which the actual chart is plotted. It is represented by a bounded rectangle. In 3D charts, it refers to the 3D base on which the columns are built. | Animation Shadow Glow Bevel Blur | _alpha _x _y _xScale _yScale
CAPTION | CAPTION refers to the heading of the chart. | Animation Font Shadow Glow Bevel Blur | _alpha _x _y
DATALABELS | DATALABELS refer to the x-axis labels of the data. | Animation Font Shadow Glow Bevel Blur | _alpha _x _y
DATAPLOT | DATAPLOT refers to the actual plot of the chart. For example, in Column 2D chart, columns are referred to as DATAPLOT. In Pie chart, it's the pies. In Bubble chart, it's the bubbles and so on. | Animation Shadow Glow Bevel Blur | _alpha _x _y _xScale _yScale
DATAVALUES | DATAVALUES refer to the plot values i.e., value of each data (line, column, bar, pie etc.), which is displayed beside the data plot. | Animation Font Shadow Glow Bevel Blur | _alpha _x _y
DIVLINES | DIVLINES are horizontal or vertical lines running through the canvas. Each divisional line signifes a smaller unit of the entire axis thus aiding the users in interpreting the chart. | Animation Shadow Glow Bevel Blur | _alpha _y _yScale
HGRID | HGRID refers to alternate color bands between two successive horizontal divisional lines. | Animation Shadow Glow Bevel Blur | _alpha _y _xScale _yScale
SUBCAPTION | SUBCAPTION refers to the sub-heading of the chart. | Animation Font Shadow Glow Bevel Blur | _alpha _x _y
TOOLTIP | TOOLTIP refers to the tool tip shown when mouse is hovered over the data plots. | Font |
TRENDLINES | TRENDLINES refer to horizontal/vertical lines spanning the chart canvas which aid in interpretation of data with respect to some pre-determined value. | Animation Shadow Glow Bevel Blur | _alpha _y _xScale _yScale
TRENDVALUES | TRENDVALUES refer to the display values of trend-lines (if any). | Animation Font Shadow Glow Bevel Blur | _alpha _x _y
VLINES | VLINES are vertical separator lines that help you separate blocks of data. These lines run through the height of the chart, thereby segregating data into different blocks. In case of bar charts, they are horizontal and run through the width of chart. | Animation Shadow Glow Bevel Blur | _alpha _x _y _yScale
XAXISNAME | XAXISNAME refers to the x-axis title of the chart. | Animation Font Shadow Glow Bevel Blur | _alpha _x _y
YAXISNAME | YAXISNAME refers to the y-axis title of the chart. | Animation Font Shadow Glow Bevel Blur | _alpha _x _y
YAXISVALUES | YAXISVALUES refers to the limit values or divisional line values, which are displayed along the y-axis of the chart. | Animation Font Shadow Glow Bevel Blur | _alpha _x _y _rotation
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> <apply toObject='Caption' styles='MyFirstFontStyle,MyFirstShadow' /> <apply toObject='Canvas' styles='MyFirstAnimationStyle' /> <apply toObject='DataPlot' styles='MyFirstShadow' /> </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: To apply multiple styles to a chart object, you need to separate the style names using comma. e.g., <apply toObject='Caption' styles='MyFirstFontStyle,MyFirstShadow' /> To apply a single style to multiple objects, you'll need to define <apply> element for each object and then assign the style for it. e.g., <apply toObject='Caption' styles='MyFirstShadow' /> <apply toObject='DataPlot' styles='MyFirstShadow' /> You CANNOT separate the object list by comma and then assign a single style to it - the following will be INVALID: <apply toObject='Caption,DataPlot' styles='MyFirstShadow' /> The style name specified during application has been defined earlier in style definition and the spelling is correct, else, FusionCharts would ignore it and log the error in Debug Window. 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.