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

Message ListMessage List     Post MessagePost Message

  How to display legend of XY chart even if 1 dataset only
Posted by Erwin Cabral on Oct-24-2012 03:56
I noticed that I can only display the legend if there are more than 2 datasets. Is there a way to display it even for 1 dataset only?

  Re: How to display legend of XY chart even if 1 dataset only
Posted by Peter Kwan on Oct-25-2012 00:37
Attachments:
Hi Erwin,

The legend box will display even if there is only 1 data set. For example, consider the "Symbol Line Chart (2)" sample code. In the original sample code, there are 3 data sets. If you comment out two of the data sets and leaving only 1 data set, the legend will still display. It will be something like the attached chart:

If you think the legend box is not displayed with 1 data set, but it is displayed with 2 data sets, is it possible to provide a short example so I can try to reproduce the problem?

Regards
Peter Kwan
symbolline2.png

  Re: How to display legend of XY chart even if 1 dataset only
Posted by Erwin Cabral on Oct-25-2012 05:08
I was able to replicate the issue when the dateset name is set to "". However, setting this to " " will display the legend. I also found out that it will only display the item in the legend with dataset names not set to "".

Below is the code snippet of symbolline2() of the sample program
-------
   // Add the three data sets to the line layer, using circles, diamands and X
    // shapes as symbols
    layer->addDataSet(DoubleArray(data0, (int)(sizeof(data0) / sizeof(data0[0]))),
        0xff0000, " ")->setDataSymbol(Chart::CircleSymbol, 9);
    layer->addDataSet(DoubleArray(data1, (int)(sizeof(data1) / sizeof(data1[0]))),
        0x00ff00, "")->setDataSymbol(Chart::DiamondSymbol, 11);
    layer->addDataSet(DoubleArray(data2, (int)(sizeof(data2) / sizeof(data2[0]))),
        0xff6600, "")->setDataSymbol(Chart::Cross2Shape(), 11);
-------

  Re: How to display legend of XY chart even if 1 dataset only
Posted by Peter Kwan on Oct-25-2012 18:56
Hi Erwin,

The behaviour you see is by design. Only data sets with a non-empty name will have an automatic legend entry, because the main purpose of the legend is to label the data representation.

Regards
Peter Kwan

  Re: How to display legend of XY chart even if 1 dataset only
Posted by Erwin Cabral on Oct-25-2012 22:59
I think the design is a good one. I was able to find a workaround anyway - setting the dataset name to a space if it is an empty string. Thanks for the help