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

Message ListMessage List     Post MessagePost Message

  Unable to set Linear scale with boxwhisker layer
Posted by herve on Nov-02-2011 23:08
Attachments:
Hello,

I'd like to display boxwhisker on a continuous X axis, meaning the boxwhisker are not evenly distributed on the x axis.

I wrote a small program generating a boxwhisker chart, but I am not able to specify correcly the x axis scale.

Below is the source code I wrote and attached is the result chart.

// Create a XYChart object of size 550 x 250 pixels
    XYChart *c = new XYChart(550, 275);

    c->setPlotArea(50, 25, 450, 200)->setGridColor(0xc0c0c0, 0xc0c0c0);

    c->addTitle("Box-Whisker plots");

    double * pQ0 = new double[2];
    double * pQ1 = new double[2];
    double * pQ2 = new double[2];
    double * pQ3 = new double[2];
    double * pQ4 = new double[2];

    pQ0[0] = 5;
    pQ0[1] = 6;

    pQ1[0] = 7;
    pQ1[1] = 9;

    pQ2[0] = 12;
    pQ2[1] = 13;

    pQ3[0] = 16;
    pQ3[1] = 16;

    pQ4[0] = 20;
    pQ4[1] = 19;

    BoxWhiskerLayer * pLayer = c->addBoxWhiskerLayer(DoubleArray(pQ1, 2),
        DoubleArray(pQ3, 2), DoubleArray(pQ4, 2), DoubleArray(pQ0, 2), DoubleArray(pQ2, 2), 0x9999ff, 0x0000cc);

    double * pXData = new double[2];
    pXData[0] = 0.65;
    pXData[1] = 0.85;

    pLayer->setXData(DoubleArray(pXData, 2));
//    pLayer->setDataWidth(10);

    c->xAxis()->setLinearScale(0.50, 1.00);

    c->makeChart("boxwhisker.png");

Questions:

1. Why the x axis doesn't start at 0.5 as specified with the setLinearScale(...) method?
2. I know I can force the width of the boxwhisker, but how chart director compute it?

Thanks
Herv
boxwhisker.png

  Re: Unable to set Linear scale with boxwhisker layer
Posted by Peter Kwan on Nov-03-2011 01:10
Hi herve,

The issue of the x-axis scale is because ChartDirector automatically sets the x-axis into "indent mode" when there is a box-whisker layer or bar layer in the chart. In indent mode, 0.5 units are reserved on both ends of the axis to ensure the box will not extend outside the plot area. The "indent mode" is designed for label based x-axis. For your axis scale, you may disable it using:

c->xAxis()->setIndent(false);

For the box width, if you have 10 boxes, ChartDirector will assume the "slot" for each box is 1/10 of the total width of the plot area. The actual box width is probably around 80% of the "slot" width so that the boxes do not touch. Again, this is designed for a label based x-axis.

For a continuous x-axis, it is impossible to automatically know the proper box width to use. For example, suppose the boxes are at x = {0, 5, 7.2, 15}, how wide should the box be?  No matter which width one uses, the boxes may overlap, or there may be wide gaps among the boxes, or both. ChartDirector will still try to "guess" the box width, but it may not be what you want. So we suggest your code to explicitly specify the box width to use.

In other words, in a continuous x-axis, the box width is just like the symbol size in a scatter chart. The size is arbitrary and cannot be determined by the data. Your code may need to provide the width to ChartDirector.

Hope this can help.

Regards
Peter Kwan