ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  is this possible?
Posted by bert on Jan-15-2016 02:57
Attachments:
I'm using Visual Studio.net 2015 and have an older version of ChartDirector (v4.1.0.0).

I need to create a bar chart (see below) from 3 sets of data. I needs to have 2 bars and
also has a "triangle" above the second bar. The triangle needs to be positioned in the
appropriate location along the Y axis, but needs to be above the second bar (it will always
be a greater value than the second bar).

Is this possible??
chart.jpg

  Re: is this possible?
Posted by Peter Kwan on Jan-16-2016 03:10
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