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

Message ListMessage List     Post MessagePost Message

  Customize the text format of legend box in XY chart
Posted by Nan on Sep-03-2013 16:30
Attachments:
Hi, is it possible that to show the sum for every dataset in the legend box ?

See the attachment, 'Head-Instability' should be 4+3+1=8, so I want to show the legend
like the following style: 'Head-Instability (8)'. Now, I just use setText() to print the
parenthesis.

And, the last legend 'Failure Rate' is from another layer(using addLayer), the red line. How
can I remove it from the legend box?

One more... Can I hide the labels of segment in my Stacked Bar Chart of the value is 1 (just
the labels when greater than 2) ?
XYchart.png

  Re: Customize the text format of legend box in XY chart
Posted by Peter Kwan on Sep-04-2013 00:36
Hi Nan,

There are several methods. One simple method is to simply use whatever you want to see in the legend as the data set name.

For example, instead of using (in C#/Java):

layer.addDataSet(myData, myColor, myName);

you may use:

//modify the myName to become myName(... sum_of_values ...)
layer.addDataSet(myData, myColor, myName + "(" + ((new ArrayMath(myData)).sum()) + ")");


Another method is to put the sum of values of all data sets in a separate array, add them as an extra field of the layer, and configure the legend entry to show the extra field. It is like:

double[] sumOfDataSets = { (new ArrayMath(myData0)).sum(), (new ArrayMath(myData1)).sum(), (new ArrayMath(myData2)).sum(), ..... };

layer.addExtraField(sumOfDataSets);
c.getLegend().setText("{dataSetName} ({dsField0})");



By default, ChartDirector will automatically add all data sets that have names to the legend box. To avoid the 'Failure Rate' to get into the legend box, there are two methods:

- Do not provide the "Failure Rate" name when adding the line (just use "")

or

- Use Layer.setLegendOrder, like:

//disable automatic legend entry for myLineLayer
myLineLayer.setLegendOrder(Chart.NoLegend);


To hide labels 1 (or below?), you would need to use custom data labels. For example (in C#):

//an array of arrays containing all the data series
double[][] allData = {myData0, myData1, myData2, .....};

for (int i = 0; i < allData.Length; ++i)
{
   for (int j = 0; j < allData[i].Length; ++i)
   {
        //replace label with an empty space
        if (allData[i][j] < 1)
             layer.addCustomDataLabel(i, j, " ");
   }
}


Hope this can help.

Regards
Peter Kwan

  Re: Customize the text format of legend box in XY chart
Posted by Nan Zhao on Sep-24-2013 17:25
Attachments:
Thanks, Peter. Most of the problems are solved.

Now...I have new questions.
1. Some of the labels of the right axis are not shown, maybe they are overlapped by my
two additional lines (the dash line, and the other is transparent). How can I let all of the
axis labels show again?
2. For the data symbol in the line chart, how can I draw a hollow circle rather than a solid
circle shape? cannot find the solution in the document.

Btw, the programming language is Python.

Peter Kwan wrote:

Hi Nan,

There are several methods. One simple method is to simply use whatever you want to see
in the legend as the data set name.

For example, instead of using (in C#/Java):

layer.addDataSet(myData, myColor, myName);

you may use:

//modify the myName to become myName(... sum_of_values ...)
layer.addDataSet(myData, myColor, myName + "(" + ((new ArrayMath(myData)).sum()) +
")");


Another method is to put the sum of values of all data sets in a separate array, add them
as an extra field of the layer, and configure the legend entry to show the extra field. It is
like:

double[] sumOfDataSets = { (new ArrayMath(myData0)).sum(), (new
ArrayMath(myData1)).sum(), (new ArrayMath(myData2)).sum(), ..... };

layer.addExtraField(sumOfDataSets);
c.getLegend().setText("{dataSetName} ({dsField0})");



By default, ChartDirector will automatically add all data sets that have names to the
legend box. To avoid the 'Failure Rate' to get into the legend box, there are two
methods:

- Do not provide the "Failure Rate" name when adding the line (just use "")

or

- Use Layer.setLegendOrder, like:

//disable automatic legend entry for myLineLayer
myLineLayer.setLegendOrder(Chart.NoLegend);


To hide labels 1 (or below?), you would need to use custom data labels. For example (in
C#):

//an array of arrays containing all the data series
double[][] allData = {myData0, myData1, myData2, .....};

for (int i = 0; i < allData.Length; ++i)
{
   for (int j = 0; j < allData[i].Length; ++i)
   {
        //replace label with an empty space
        if (allData[i][j] < 1)
             layer.addCustomDataLabel(i, j, " ");
   }
}


Hope this can help.

Regards
Peter Kwan
Failure Rate---(PLATO)_2013-09-24_17-18-15.png

  Re: Customize the text format of legend box in XY chart
Posted by Peter Kwan on Sep-24-2013 23:31
Hi Nan,

1. If the mark line has a label, and it overlaps with an axis label, the mark label will override the axis label and cause the axis label to be hidden. In your case, your mark labels probably overlaps with some axis labels, causing the latter to disappear. Although the part of the mark labels that overlaps with the axis labels are just space characters, ChartDirector will still hide the axis labels.

To solve the problem, one method is to put the mark labels at other locations. For example, you may put them inside the plot area. There is an example below:

http://www.advsofteng.com/doc/cdcom.htm#markzone2.htm

In the above example, the mark labels is on top of the line centered on the plot area. You may use setAlignment to choose other positions too, such as on the right side but internal to the plot area. In this way, the mark label cannot overlap with the axis label and so the axis label will not be hidden.

If you must put the mark at your current position, one method is to put the mark somewhere else (I suggest on the left side of the plot area and internal to the plot area), and then use CDML to "shift" the mark to your current position. It is like:

Set m = c.yAxis().addMark(70, &H800080, "<*xoffset=" & (c.getPlotArea().getWidth() + 30) & "*>My Label")
Call m.setAlignemtn(cd.Left)

Note the <*xoffset=xxxx*> above, which shifts the mark to the right so that it moves to outside the plot area.


2. To draw a hollow symbol, please use transparent as the fill color, and red as the edge color. For example:

Call myLineLayer.getDataSet(0).setDataSymbol(cd.CircleSymbol, 11, cd.Transparent, &Hff3333)


Hope this can help.


Regards
Peter Kwan