Chart FX for Java not only reads chart data from XML, but can also read chart properties to set visual attributes and formatting for your charts. The XML property files can be read and applied to a chart by utilizing the Import method. The following is used to set properties for a chart:
chart1.importChart(FileFormat.XML, application.getRealPath("/ChartFX") + "/ChartProps.xml");
|
A formal schema has not been created, however each property is a tag, and properties for sub objects (series, point, axis, etc.) should be sub tags. When
customizing per series or per point attributes there is no tag per series, instead an index attribute is used. Here is a sample of a property XML file.
Note: When specifying an axis property, you must use the integer index parameter instead of constants such as X, X2, Y or Y2.
<CHARTFX> <VOLUME>35</VOLUME> <VOLUME>35</VOLUME> <TITLES> <TITLE> <TEXT>My First Chart</TEXT> </TITLE> </TITLES> <SERLEGBOXOBJ> <DOCKED>Left</DOCKED> <DRAWINGAREA>true</DRAWINGAREA> <FONT> <NAME>Verdana</NAME> </FONT> <ALIGNMENT>Center</ALIGNMENT> </SERLEGBOXOBJ> <SERLEGBOX>True</SERLEGBOX> <SERLEG> <LEGEND>Sales</LEGEND> <LEGEND>Projected</LEGEND> </SERLEG> <SERIES> <SERIES index="0"> <BORDER>True</BORDER> <GALLERY>LINES</GALLERY> </SERIES> <SERIES index="1"> <BORDER>True</BORDER> <GALLERY>Lines</GALLERY> </SERIES> </SERIES> <POINT> <POINT series="1" point="2"> <COLOR>Red</COLOR> <MARKERSHAPE>Rect</MARKERSHAPE> </POINT> </POINT> <STRIPES> <STRIPE> <AXIS>0</AXIS> <TO>20</TO> <FROM>30</FROM> </STRIPE> </STRIPES> </CHARTFX>
|
Note: Using the Export method, you can export the properties of a chart to an XML file to examine how Chart FX will read the same information.
Setting Chart FX for Java Properties using XML
There are a number of different scenarios for setting Chart FX properties using XML. This document will not enumerate all the properties in the API; rather it will give examples of each of the categories of properties.
- Simple Properties
- Compound Properties
- Simple Collection Properties
- Collection Index Properties
- Point Attribute Properties
- External Object Properties
- Extensions
Simple Properties
This represents the most basic type of property setting. These properties are set in a very straight forward fashion; use the property name for the opening and closing tag and the value in the middle. For example, to set the Gallery property you could use the following code:
This category includes all the general chart settings that are not related to a particular series, point or axis object.
Compound Properties
A compound property is one that contains multiple attributes. A property of this genre will contain tags for each attribute and its value inside of the parent property’s tag. For example, when setting fonts there can be numerous settings including the name and size of the font.
<FONT> <NAME>Bookman Old Style</NAME> <SIZE>15</SIZE> </FONT>
|
You should be cognizant of the fact that fonts are usually set for a particular chart element (unless, of course, you are setting the font for the chart object itself). Therefore the above XML code will be included inside of a parent object; like an axis or a title.
Simple Collection Properties
Simple collection objects are those objects that don’t use a particular index, therefore the order they appear in the XML is significant. For instance, in the following stripe collection sample the "OrangeRed" stripe is added to the chart as the first stripe and the "Yellow" Stripe is added as the second stripe. This variety of objects includes constant lines and stripes. Notice that the various items in the collection are not indexed with any particular number:
<STRIPES> <ITEM> <COLOR>Red</COLOR> <TO>5</TO> <FROM>2.5</FROM> <AXIS>2</AXIS> <URL>http://support.softwarefx.com</URL> </ITEM> <ITEM> <COLOR>Yellow</COLOR> <TO>8</TO> <FROM>7</FROM> <AXIS>2</AXIS> </ITEM> </STRIPES>
|
Title settings also belong in this category. Notice in the following sample how the font settings are nested inside of the parent TITLES tag.
<TITLES> <ITEM> <TEXT>Chart Title</TEXT> <COLOR>Purple</COLOR> <FONT> <NAME>Bookman Old Style</NAME> <SIZE>15</SIZE> </FONT> </ITEM> </TITLES>
|
Collection Index Properties
What differentiates this class of properties from the previous type is the indexed number. This means that the order in the XML is not significant. The objects in the collection will be added to the chart based on their index number. It is also important to note that you may skip index numbers, as the chart will simply add the objects in ascending indexed order without regard for consecutive numbers. This allows you to skip numbers in order to objects later. This category includes such items as series settings and axis settings. You will notice in the following sample that each item in the collection receives a unique index to distinguish it from the other items in the collection.
<AXIS> <ITEM index="0"> <STYLE>SingleLine, BreakZero, LongTick</STYLE> <AUTOSCALE>False</AUTOSCALE> <LABELSFORMAT> <DECIMALS>0</DECIMALS> </LABELSFORMAT> <GRIDLINES>True</GRIDLINES> <MIN>0</MIN> <MAX>50</MAX> </ITEM> <ITEM index="2"> <TICKMARK>Cross</TICKMARK> <GRIDLINES>True</GRIDLINES> </ITEM> <ITEM index="3"> <STYLE>SingleLine, BreakZero, LongTick</STYLE> <AUTOSCALE>False</AUTOSCALE> <LABELANGLE>45</LABELANGLE> <POSITION>Far</POSITION> <FONT> <SIZE>12</SIZE> </FONT> <TEXTCOLOR>Red</TEXTCOLOR> <MIN>-12</MIN> <MAX>25</MAX> </ITEM> </AXIS>
|
Point Attribute Properties
Point attributes require two indexed numbers in order to set their properties. These two numbers represent the specific series and point whose attributes are being set. Please note that when setting point attributes you can set either a specific point of a particular series, or you may set a certain set of attributes that will be common to all indexed points of all the series in the chart. In the latter case the series index should be set to -1, as follows:
<POINT> <ITEM series="0" point="2"> <MARKERSHAPE>InvertedTriangle</MARKERSHAPE> <MARKERSIZE>7</MARKERSIZE> <COLOR>Yellow</COLOR> </ITEM> <ITEM series="-1" point="0"> <ALTERNATECOLOR>Bisque</ALTERNATECOLOR> <COLOR>Red</COLOR> </ITEM> </POINT>
|
Additional Notes
It is important to understand that when you import an XML file you must specify all the settings that want to be included in the chart. For example, if you were displaying a Pie chart and the user clicks a button to import a bar chart from an XML file, if the XML does not explicitly set the gallery property to Bar the chart will retain the gallery setting from the previous chart. This is particularly important to keep in mind in the case that you exported an existing Bar chart to an XML file and then you desire to re-import it. Unlike binary chart files, the XML does include default chart settings (in order to keep the files smaller in size).
|