Chart Style Idea

Overview

While configuring your elements' visual appearance you may have encountered a problem of adjusting your elements' options, especially when these options are common for a whole group of elements. For this case we have a styles node, in which you can describe the style of your color tooltips, labels, markers, i.e. fully configure the view of your chart.

In this section we will describe main parts of chart style and demonstrate how style can be created and applied. The main idea of styles is to segregate visualization and data definition. Visual appearance of elements is defined using certain styles and then you just apply the style to the certain data elements. Style can be applied to data series, data category or single element. Also, styles are used to make charts interactive, you can define how elements will be displayed by default, when selected, when user moves cursor over an element, etc.

Please see all information about element styles in Styles sections of approriate element tutorials and XML Reference, for example:

 

Style Idea and Demonstration

Style is a named set of confuguration nodes for some element, each style holds all unique settings for the element, typically style consists of a main part and so-called states.

Each style should have a unique name among the styles of the same type, you can create <bar_style name="Style1"/> and <marker_style name="Style1"/> at the same time.

Main part holds all default settings for the element, and states define how element looks like when it is hovered, pushed, selected and so on. The number of states supported may differ from style to style.

Most convenient way of using style is to define the settings that wouldn't change (like a marker shape, for example, or line thickness) and create a named style in <styles/> node.

Later, when you create an element you specify the style attribute and set its value to style name.

Let's go through the creation of a simple bar chart to understand how everything works.

Create a Chart

At first we just create a bar chart with several columns without configuring them. We adjust chart's type:

XML Syntax
Plain code
01 <chart plot_type="CategorizedHorizontal" />

Now we need to create some bars. That is very simple. We create data node, specify Series name and type, add 5 points and set names and values for them:

XML Syntax
Plain code
01 <data>
02   <series name="Series 1" type="Bar">
03     <point name="Point 1" y="637166" />
04     <point name="Point 2" y="721630" />
05     <point name="Point 3" y="148662" />
06     <point name="Point 4" y="78662" />
07     <point name="Point 5" y="90000" />
08   </series>
09 </data>

That's all! Although we have changed only some attributes our chart already works:

Live Sample:  Style first chart 1

to top

Define reusable settings and put them in Style

Now let's configure one of the elements: let it be the first bar. We will change its color in both normal and hover states.

We create the corresponding subnode in bar_style node, and define that our bar should have DarkBlue color in normal mode and Aqua color when we hover on it. So the XML for bar now is as follows:

XML Syntax
Plain code
01 <styles>
02   <bar_style name="Style 1">
03     <states>
04       <normal>
05         <fill enabled="true" type="solid" color="DarkBlue" />
06       </normal>
07       <hover>
08         <fill enabled="true" type="solid" color="aqua" />
09       </hover>
10     </states>
11   </bar_style>
12 </styles>

to top

Apply a Style

Now when we have created our style let's apply it to bar. In point node we create style attribute and enter our style's name there:

XML Syntax
Plain code
01 <point name="Point 1" y="637166" style="Style 1" />

Here is the result:

Live Sample:  Style first chart 3

You can also define style for <series> or in <bar_series> to set style for all series or all series in chart.

to top

Styles Inheritance

Whenever you create a style you may want to create it basing on another style - to do this just specify parent attribute and set its value to the name of the style you want to inherit. Sample XML:

XML Syntax
Plain code
01 <styles>
02   <bar_style name="MainStyle">
03     <fill type="Solid" color="Red" />
04   </bar_style>
05   <bar_style parent="MainStyle" name="ChildStyle" />
06 </styles>

If you use XML above - all bars with style="ChildStyle" will have Red fill as well as all styles with style="MainStyle".

to top

to top