DataStyle Property
The DataStyle property is used to control how Chart FX takes the information from a data source. In other words, this property specifies what field types should be considered when data is passed to the chart. This property may be used for, transposing data, reading values and X-values, setting legends, etc.
For example, if the following SQL statement:
SELECT Month,Product1,Product2 FROM Sales
|
returns 5 records, the chart will contain 2 lines (assuming it is a line chart) and each line will have 5 point markers. If you want to create a chart with 5 lines (each with two point markers) you would set the Transpose datastyle before the setDataSource call:
chart1.setDataStyle(chart1.getDataStyle() | DataStyle.TRANSPOSE);
|
Another useful DataStyle flag is ReadXValues, which instructs Chart FX that the data read will include both values and x values.
Lets say that your data looks like this, and you want to plot an XY chart:
By just doing:
chart1.setDataStyle(chart1.getDataStyle() | DataStyle.READXVALUES);
|
Chart FX will read the data as if you have done:
chart1.setXValue(0,0,1); chart1.setValue(0,0,200); chart1.setXValue(1,0,3); chart1.setValue(1,0,400); chart1.setXValue(0,1,2); chart1.setValue(0,1,100); chart1.setXValue(1,1,6); chart1.setValue(1,1,300);
|
DataType Property
The DataType property is an array property that indicates the type of every field and how it should be extracted from the SQL query and used in the chart. For example, in a 5 field SELECT statement such as:
SELECT year,sales,projected,returns,name FROM Sales
|
The Chart FX default behavior is that the year field will be considered another series since it is a numeric field. Instead, we want this field to be used as a label in the X-axis tick marks. Also, since this SQL query is also being used to fill a grid control (which contains more information than the chart) we do not want to get rid of the returns and name fields in the query but we also don't want them to be used anywhere in the chart. However, the Chart FX default behavior would cause these fields to be appended as X-axis labels.
We can easily override the Chart FX default behavior by setting DataType property as follows, using the setDataType method:
chart1.setDataType(0,DataType.LABEL);
chart1.setDataType(1,DataType.VALUE); chart1.setDataType(2,DataType.VALUE);
chart1.setDataType(3,DataType.NOTUSED); chart1.setDataType(4,DataType.NOTUSED);
|
|