Hi bert,
ChartDirector 5.0 or above has a function Layer.alignLayer that can be used to align one
layer (such as the scatter layer for the symbols) with the data set of a bar layer.
For earlier versions of ChartDirector, you would need to shift the scatter symbols with
your own code. By default, the scatter labels will be at the center of the bar group (for 2
bars, it would be in the middle of the two bars). You would need to shift the x-
coordinates by an amount so that it aligns with the second bar. The amount to shift
depends on the bar gap and the sub-bar gap (see BarLayer.setBarGap on these two
parameters), which can be computed using the following function (written in C#):
//A utility function to compute the amount of shifting required
double boxOffset(double barGap, double subBarGap, int noOfDataSets, int
currentDataSet)
{
return 0.5 * (1 - barGap) * (2 * currentDataSet - noOfDataSets + 1) / (noOfDataSets
- subBarGap);
}
So for your case, the code for adding the symbols is like:
ScatterLayer layer = c.addScatterLayer(null, yData, "", Chart.TriangularSymbol, 11,
0x0000cc);
// assume the default bar gap of 0.25 and sub-bar gap of 0.2
double offset = boxOffset(0.25, 0.2, 2, 1);
layer.setXData(offset, yData.Length - 1 + offset);
For the x-axis labels, instead of using Axis.setLabels, you need to use:
c.xAxis().setLinearScale2(0, yData.Length, labels);
Hope this can help.
Regards
Peter Kwan |