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

Message ListMessage List     Post MessagePost Message

  4 Quadrant Graph with Labels
Posted by nicole on May-30-2012 18:51
Attachments:
Hi,

I just want to ask if ChartDirector is capable of generating a graph like the image shown
below. If yes, how can I achieve that?


Thank you very much!
sample quadrant.png

  Re: 4 Quadrant Graph with Labels
Posted by Peter Kwan on May-30-2012 22:46
Hi nicole,

It is a standard Polar Scatter Chart in ChartDirector. Please refer to the "Polar Scatter Chart" sample code for an example.

To create a similar chart, you may modify the sample code to fit what you need, such as changing the chart size, removing the labels, changing the colors, changing the symbol type and size, adding labels to some symbols (using PolarLayer.setDataLabelFormat), etc..

Hope this can help.

Regards
Peter Kwan

  Re: 4 Quadrant Graph with Labels
Posted by nicole on May-30-2012 23:35
Hi,

Pardon me if I'm a newbie but is there any way to add labels in any position inside the
quadrant just like in the image I attached above? Looking at the samples, it seems like the
position of the labels cannot be adjusted?


Thank you so much!

  Re: 4 Quadrant Graph with Labels
Posted by Peter Kwan on May-31-2012 02:13
Hi nicole,

The position of the labels can be adjusted by using TextBox.setAlignment and Box.setPos. For example, in C++:

PolarLineLayer *layer = c->addLineLayer(...);
layer->setAngles(.....);
layer->setLineWidth(0);
layer->setDataSymbol(Chart::TriangleSymbol, 11);

for (int i = 0; i < noOfPoints; ++i) {
    TextBox *b = layer->addCustomDataLabel(i, myLabels[i], "arial.ttf", 8, 0x000000);
    b->setAlignment(Chart::BottomLeft);
    b->setPos(-11, 0);
}

Hope this can help.

Regards
Peter Kwan

  Re: 4 Quadrant Graph with Labels
Posted by nicole on May-31-2012 23:51
Attachments:
Hi,

Thanks for your reply. Can you please explain how the setPos works? I mean does it
entail x
and y coordinates on the graph itself or the x and y coordinates of the pixels of the
picture?
Also, based from the description of the function of addCustomDataLabel, it adds a
custom data label to a data point. However, what I need are fixed labels/texts at fixed
positions in the graph which have no connection to the data points. Can this be done?
Moreover, only the first label appears as shown in the image below.


My code is:

// Add scatter layer, using 15 pixels red (ff33333) X shape symbols
    ScatterLayer *layer = c->addScatterLayer(DoubleArray(dataX0,
sizeof(dataX0)/sizeof(dataX0[0])),
        DoubleArray(dataY0, sizeof(dataY0)/sizeof(dataY0[0])), "Group A",
        Chart::Cross2Shape(), 15, 0xff3333);

TextBox *happy = layer->addCustomDataLabel(0, 0, "Happy", "arial.ttf", 8,
0x000000);
happy->setAlignment(Chart::BottomLeft);
happy->setPos(-11, 0);

TextBox *excited = layer->addCustomDataLabel(1, 1, "Excited", "arial.ttf", 8,
0x000000);
excited->setAlignment(Chart::BottomLeft);
excited->setPos(11, 0);


Can you please help me? Thanks!
fourq.png

  Re: 4 Quadrant Graph with Labels
Posted by Peter Kwan on Jun-01-2012 00:15
Hi nicole,

I was thinking you were using a polar scatter chart. But according to the code you provided, you are using an XYChart. For an XYChart scatter layer, the addCustomDataLabel should be called with the first argument always zero, like:

TextBox *happy = layer->addCustomDataLabel(0, 0, ....);
TextBox *excited = layer->addCustomDataLabel(0, 1, ....);

To add labels at "fixed positions", you still need to tell ChartDirector where are the positions. Suppose the x and y coordinates of the "fixed positions" are in the dataX0 and dataY0 arrays. The code is then:

ScatterLayer *layer = c->addScatterLayer(DoubleArray(dataX0, noOfPoints),
   DoubleArray(dataY0, noOfPoints),  "", Chart::SquareShape, 1, Chart::Transparent,
   Chart::Transaprent);

Basically, the code is the same as what you are doing, except that I change the symbol to transparent, so there is no symbol on the chart.

Then you would need to tell ChartDirector where would you like to put the text relative to the point. It can be Chart::Center on the point, or to the left of the point (use Chart::Right), or at other positions (use Chart::Left, Chart::TopLeft, Chart::TopRight, Chart::Left, Chart::BottomLeft, Chart::BottomRight, Chart::Bottom) relative to the point. If all of these positions are near but not exactly what you want, you can use Box.setPos to shift the position. For example, consider the following code:

happy->setAlignment(Chart::BottomLeft);

It means the text is at the top right corner of the symbol. More accurately, it means the bottom left corner of the text is aligned with the top right corner of the symbol. (If you left align several lines of text with respect to a vertical line, it means all the lines is at the right side of the line, so that the left side of all the text aligns. So left alignment means the text is at the right side of the reference point, and bottom-left alignment means the text is at the top-right side of the reference point.)

Now, if you also added the line:

happy->setPos(-11, 0);

It means after putting the text at the top right corner of the symbol, the text is shifted 11 pixels to the left (the x-coordinate is shift by -11 pixels).

You can adjust the alignment and setPos until you get the position you want the text to be at.

Hope this can help.

Regards
Peter Kwan

  Re: 4 Quadrant Graph with Labels
Posted by nicole on Jun-01-2012 15:03
Attachments:
Hi Peter,

Thanks for your reply. Sorry I opted for XYChart because it suits my needs better.
However, I think what you're suggesting is still dependent on the data points. What I need
are texts that are in the background of the graph itself, which have no connection with the
data points just like in the images below. I need constant texts in the graph and for every
iteration, the data points (denoted by the red X) vary but the fixed texts do not.. Is this
possible?


Thank you so much. Sorry for the trouble.
sample quadrant.png
sample quadrant2.png
sample quadrant2.png

  Re: 4 Quadrant Graph with Labels
Posted by nicole on Jun-01-2012 17:47
Hi Peter,

I got what I need. I used c->addText instead. Thanks for your help. However, is there any
way for an XYChart to have a circular grid? If so, how do you do it?


Thanks!

  Re: 4 Quadrant Graph with Labels
Posted by Peter Kwan on Jun-02-2012 10:00
Hi nicole,

With a PolarChart, it automatically has circular grids. If you prefer to use the XYChart, you would need to draw the grid by adding circles onto the chart. For example:

DrawArea *d = c->getDrawArea();
d->circle(cx, cy, radius, radius, edgeColor, fillColor);

Note that with the above code, the circle is drawn on the backgroud. So to see the circle, your plot area must be configured to be Chart::Transparent.

If you prefer to add the circle on the foreground, you may add all your data to the chart first, then use:

DrawArea *d = c->makeChart();
d->circle(cx, cy, radius, radius, edgeColor, fillColor);

Hope this can help.

Regards
Peter Kwan