Passing numeric values using the Chart FX for Java API is as simple as opening a communication channel using the openData method, setting the values and then closing the communication channel using the closeData method. You can pass data using the API through any loop command (while, for, etc.) supported in your development environment.
Important Note: This section will explain how to pass numerical information to Chart FX, if you want to set legends and other text information to the chart, please refer to Axis Labeling - Understanding a Categorical Axis in this help file. This section also describes how to pass information to the majority of chart types provided by Chart FX. If you're creating special chart types, such as financial, scatter and other, please refer to later chapters in this help file, as additional properties need to be set to create these charts appropriately.
Passing Data using the Value property
Sometimes the easiest or most convenient way to pass numerical data to Chart FX
for Java is to use the setValue method, which allows you to set the
numerical value for a point in a particular series in the chart.
The setValue method takes the index of the series (zero based) and the
index of the point you want to populate (zero based), and the value. For
example, if you want to set a value of 40 for point 3 of series 2, you must use
the setValue method as follows:
Please note the setValue method will have no effect unless you invoke it
between an openData and closeData methods. For example, if you want to set
points to the entire chart, you can loop through the points and use the
setValue method as follows:
chart1.openData(COD.VALUES, 3, 3); for (int i=0;i<3;i++) for (int j = 0;j<3;j++) {
chart1.setValue(i, j, java.lang.Math.random()* 100) }
chart1.closeData(COD.VALUES);
|
Unknown Number of Points
Sometimes, knowing the number of points that the chart will hold is not possible and you'll end up in a situation where you don't know how to set the third parameter in the openData Method.
For example, if you're retrieving values from a database according to end users requests, it will be impractical to fetch all records and count them just to know the value Chart FX for Java needs to open the communications channel. The OpenData method supports a setting called COD.UNKNOWN, which will force Chart FX for Java to allocate memory dynamically as you pass numeric values to it. The following code shows you how to use the COD.UNKNOWN setting appropriately.
chart1.openData(COD.VALUES, 1, COD.UNKNOWN); int j = 0; while (Fetching Records) { chart1.setValue(0, J, value); j = j + 1; } chart1.closeData(COD.VALUES);
|
Note: Please notice that COD.UNKNOWN is valid only for an unknown number of points. The number of series in the chart must be preset when calling the openData method.
Axes Rescaling
When data is loaded to the chart, by default, Chart FX for Java automatically adjusts the axes Min and Max to guarantee that every value is inside the range. This behavior is controlled by the axes setAutoScale method.
However, if a new set of values is loaded on the same chart,Chart FX will adjust the Min and Max again, only increasing when necessary but never decreasing them, which can affect the chart visualization. To force the Min and Max to be recalculated based on the new set of data, call the axes resetScale method before loading the new data.
Hidden Points
Another interesting feature of Chart FX for Java is the ability to create hidden points in the chart. Although Chart FX for Java forces the same amount of points per series, you may specify hidden points to create the illusion of some invisible points in the chart. All you need to do to create a hidden point is to assign the Chart.HIDDEN constant when using the setValue method toassign the numeric value to a point.
chart1.setValue(0, 3, Chart.HIDDEN);
|
Note: Remember to use the openData and closeData Methods when setting values to the chart.

Existing Values in the Chart
If you've already populated the chart and all you want to do is change an isolated value, you may do so without sending all the data again. The openData method supports a setting called COD.UNCHANGE that will cause the data memory to remain intact, yet allowing you to change values in the chart.
For example, if you want to change programmatically the numeric value for point No. 4 in the third Series your code should look like:
chart1.openData(COD.VALUES, COD.UNCHANGE, COD.UNCHANGE); chart1.setValue(2, 3, 560); chart1.closeData(COD.VALUES);
|
|