How to Use Styles | ||||||||||||||||||||||||||||||||||||||||||||||||||||
To use the Styles feature in FusionWidgets XT, you first need to define your styles in the XML/JSON data document. To define Styles, the following data is used: |
||||||||||||||||||||||||||||||||||||||||||||||||||||
<chart> <!-- Your data here --> <styles> <definition> <style name='MyFirstFontStyle' type='font' font='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' /> { "chart": {}, "styles": { "definition": [ { "name": "MyFirstFontStyle", "type": "font", "font": "Verdana", "size": "12", "color": "FF0000", "bold": "1", "bgcolor": "FFFFDD" }, { "name": "MyFirstAnimationStyle", "type": "animation", "param": "_xScale", "start": "0", "duration": "2" }, { "name": "MyFirstShadow", "type": "Shadow", "color": "CCCCCC" } ], "application": [ { "toobject": "Caption", "styles": "MyFirstFontStyle,MyFirstShadow" }, { "toobject": "Canvas", "styles": "MyFirstAnimationStyle" }, { "toobject": "DataPlot", "styles": "MyFirstShadow" } ] } } |
||||||||||||||||||||||||||||||||||||||||||||||||||||
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 code. FusionWidgets XT will not recognize any style definition outside the <styles> parent element. Children to the <styles> element are <definition> and <application> elements. As the name suggests, <definition> element contains your custom styles definition for the chart while under the <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/JSON 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
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' .../> "definition":[{ "name":"MyFirstFontStyle", "type":"font", "face":"Verdana", ...}, |
||||||||||||||||||||||||||||||||||||||||||||||||||||
There are no restrictions on the style name, barring the pointers below:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
type | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Each style needs to be defined as to what type it is. The type defines what this style is going to do. FusionWidgets XT 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: |
||||||||||||||||||||||||||||||||||||||||||||||||||||
<style name='MyFirstFontStyle' type='font' face='Verdana' .../> <style name='MyFirstAnimationStyle' type='animation' .../> <style name='MyFirstShadow' type='Shadow' .../> "definition":[{ "name":"MyFirstFontStyle", "type":"font", "face":"Verdana", ...}, |
||||||||||||||||||||||||||||||||||||||||||||||||||||
If you do not define a style type for a particular style, FusionWidgets XT will ignore the style definition and log an error in the Debug Window. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
Other Attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||||
The rest of the attributes of 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 Objects section of the XML Sheet for each chart. For example, we've the following chart objects for Angular Gauge: |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
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/JSON 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> "application":[{ "toobject":"Caption", "styles":"MyFirstFontStyle,MyFirstShadow" }, |
||||||||||||||||||||||||||||||||||||||||||||||||||||
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:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
Applying custom defined Styles to annotation objects | ||||||||||||||||||||||||||||||||||||||||||||||||||||
You can also apply custom defined Styles to annotation objects. Whenever you have to apply Styles to annotations, you have to make an annotation group, put the annotations in the annotation group and then just name the ID in the toObject attribute of the <apply> element. For a detailed discussion (with example) on how to apply Styles to annotations, please have a look at the Using Styles page of the Annotations section. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
Note: In JavaScript charts, customized animation, shadow, glow, bevel and blur style types are not available. JavaScript charts provide limited support for customized Font style. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
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. |