Hi Deepankar Sharma,
If you are not plotting a lot of data points (less than 1000 points), you may consider to draw each point in a separate scatter layer. In this way, every symbol can be of different color. It is like (in Java):
for (int i = 0; i < myXData.length; ++i) {
ScatterLayer layer = c.addScatterLayer(new double[] { myXData[i] }, new double[] { myYData[i] }, "", Chart.DiamondSymbol, 13, myColors[i]);
layer.setSymbolScale(.....);
}
In the above, myColors is an array of colors you would like your symbols to have. In many applications, the coloring rules are pre-defined by the nature of the application, and not related to the data. In this case, you may want to create your own function to obtain the colors from the data values.
For example, if you would like to plot a weather chart with temperature, the 35C (eg. red color) or above may be considered as hot, while -10C may be considered as cold (eg. blue color). Even if all the data values are 0C to -20C (because it is measuing winter temperature), the application may not want to color 0C as a hot point (red color). If the colors are automatically determined by ChartDirector, it might look at the data range 0 to -20, and consider 0 to be red and -20 to be blue, and this may not be natural to the application.
If instead you want ChartDirector to automatically assign colors to the data values, you may create a dummy chart with a dummy contour layer, so as to obtain the colorAxis to map values to colors. An example is:
//dummy 1 x 1 chart just to get the color aixs
XYChart c2 = new XYChart(1, 1);
ColorAxis cAxis = c2.addContourLayer(null, null, null).setColorAxis(0, 0, 0, c.getPlotArea().getHeight(), 0);
cAxis.setLinearScale(new ArrayMath(myColorData).min(), new ArrayMath(myColorData).max());
c2.makeChart3();
for (int i = 0; i < myXData.length; ++i) {
ScatterLayer layer = c.addScatterLayer(new double[] { myXData[i] }, new double[] { myYData[i] }, "", Chart.DiamondSymbol, 13, cAxis.getColor(myColorData[i]));
layer.setSymbolScale(.....);
}
//As the color scale is automatically determined by ChartDirector, you may want to display
//a color scale so the user can read the value from its color.
c.addContourLayer(null, null, null).setColorAxis(450, 65, Chart.TopRight, c.getPlotArea().getHeight(), Chart.Right).setLinearScale(cAxis.getMinValue(), cAxis.getMaxValue());
Hope this can help.
Regards
Peter Kwan |