An XY Plot is a chart that shows the relationship or degree of relationship between numeric values in several series, or plots two groups of numbers as one series of x,y coordinates.
Because each point in an XY Plot is defined by two coordinates (x, y), you must make additional calls to be able to pass numeric data accordingly.
Passing Data to a scatter plot with the Value and XValue properties
The only special case when passing data to an XY Plot is
that you're going to make two OpenData method calls
(one with COD.Values or y coordinate and another one
withCOD.XValuesor x coordinate) and finally use the
Value property to assign the appropriate y values and
the XValue property to assign the x values of each
point in the chart. The source code should look as follows:
chart1.setGallery(Gallery.LINES);
chart1.openData(COD.VALUES, nSeries, nPoints); chart1.openData(COD.XVALUES, nSeries, nPoints);
for (int i=0;i<nSeries;i++) for (int j=0;j<nPoints;j++) { chart1.setValue(i, j, <Y Coordinate Value>); chart1.setXValue(i, j, <X Coordinate Value>); }
chart1.closeData(COD.VALUES); chart1.closeData(COD.XVALUES);
|
Please remember that in an XY Plot chart the X-axis becomes
a numerical (not a categorical) axis that you can customize
with the Axis object properties. This means that instead
of legends you will be setting scales, min, max and other
numerical values to the X-axis.
XY Plots - Frequently Asked Questions
Which Chart Types are supported as XY Plots?
Although the most common use for XY Plots are Scatter charts (or
Point charts) , Chart FX for Java allows you to change to the
following chart types when you set data values as x,y coordinates:
Line, Curve, Area, Step Lines, Surface, Bubble, Contour and
Curve Area.
This means that if you want an XY Plot to show connected
lines all you need to do is change the Gallery property
to Lines.
How can I instruct a DataSet that I'm creating a scatter plot?
Normally, when a chart is bound to a DataSet or if you use
a Data Command or are reading from a file (text or XML) to retrieve
data and populate the chart, Chart FX for Java will assume
that you want to create a regular chart type and not an XY
Plot. This means that if you are connecting to a database
that contains X and Y coordinates for an XY Plot, Chart FX
for Java by default will create a chart with two series instead
of an XY Plot.
This default behavior can be overwritten using the DataType
property. For example, if you have a SQL Statement like:
SELECT YValue,XValue FROM MyTable
|
You can set the DataType property as follows:
chart1.setDataType(0, DataType.VALUE); chart1.setDataType(1, DataType.XVALUE);
|
This will force Chart FX for Java to assign the information
appropriately for the XYPlot.
Important Note: The DataType property must
be set before you assign the DataSource property to
the chart control.
Can I force lines to display the same color as point markers?
Yes, you may use the TypeMask property to force Chart FX to
display lines in the same color as the point markers instead
of black, as follows:
chart1.setTypeMask(chart1.getTypeMask() | ChartType.COLOR_LINE);
|
Can I use different point markers in a scatter plot?
Yes, please refer to the MarkerShape property supported by
the SeriesAttributes and PointAttibutes objects.
Can I highlight points in a scatter chart? Say for example,
I have a certain limit I want to control and highlight points
that plot above that limit.
The answer to this question not only applies to scatter charts,
but all types of charts in Chart FX for Java. You have two
options:
1) Use Chart FX for Java "Constant Lines and Color Stripes"
feature to highlight the limit or range, respectively.
2) You may change the color of the points that plot above
that limit. If this is what you want, you can force Chart FX for Java to assign different colors for each point in the
chart. The code should look like:
int totSeries = chart1.getNSeries(); int totValues = chart1.getNValues(); PointAttributes redPoints = new PointAttributes(chart1); redPoints.setColor(java.awt.Color.red); PointAttributes bluePoints = new PointAttributes(chart1); bluePoints.setColor(java.awt.Color.blue); for (int i=0;i<totSeries;i++) for (int j=0;j<totValues;j++) { if (chart1.getValue(i,j) >= myLimit) {
chart1.setPoint(i,j,redPoints); } else {
chart1.setPoint(i,j,bluePoints); } }
|
|