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

Message ListMessage List     Post MessagePost Message

  Add extra labels to percentage bar chart
Posted by Chris on Mar-19-2013 19:11
Hi

I have put together a horizontal percentage bar chart and want to add more supporting
labels. I have used the .setAggregateLabelFormat for adding a mean value after the bars
and obviously have the x-axis labels.  Is it possible to push the x axis labels left and add
another set of labels in a column (lined up with the bars) that have say a count of values
in.  The only way I can think of is to format the x-axis labels to do it - e.g  "q1     16" and
then position a textbox above the 16 to say count.

Thanks

Chris

  Re: Add extra labels to percentage bar chart
Posted by Chris on Mar-19-2013 19:23
Hi

Tagged to that, I am also trying to make the legend wide (to match the barchart) which I
can do sizewise, is it possible to autospace or specify anchor points for legend items (still
bunched on the left), and can you add other labels inside the legend area say top left or
top right?

thanks
Chris

  Re: Add extra labels to percentage bar chart
Posted by Chris on Mar-19-2013 20:47
My apologies missed off the bit where I have an array with one value in from a db and I
want to have it within the textbox - Set textbox = c.addText(70, 65,"Overall Satisfaction: "
& col8, "arialbd.ttf", 8) seems to throw a Type mismatch error, SQL value was decimal(8,2)
format, any thoughts?

  Re: Add extra labels to percentage bar chart
Posted by Peter Kwan on Mar-19-2013 23:10
Hi Chris,

If you want to have the axis label as "q1     16", you can simply use this as the axis label. In other words, you may combine the two text strings "q1" and "16" first (possibly with some space in between), before passing them to ChartDirector as the axis label.

If you do not want to use space characters to combine the two text strings, you may insert CDML to combine the two text strings. The sample code "Donut Chart" contains an example in which CDML is used to combine the text strings so that they align properly. This example uses the text strings in the legend box, but you can use them as axis labels too.

Another method is to use a label table like in the "Data Table" sample code. Instead of docking the table to the horizontal axis, you may modify the code to dock the table to the vertical axis.

For the legend box, you can set it to any width you like using Box.setWidth, but it may not use all the widths. For example, if the width is 1000 pixels, but it only has one item with the name "ABC" in 10pt Arial font, it is hard to use all the width. Instead, it will use only as much width as necessary but not exceeding 1000 pixels.

If your legend box is using horizontal layout, the legend entries will flow from left to right, and when they exceed 1000 pixels, the entries will wrap to the next line.

If your legend box is using grid layout (see BaseChart.addLegend2), the legend box will be subdivided horizontally into cells of equal size. Each legend entry will be placed in one cell. The legend entry within a cell flows from left to right. It means within a cell, the legend entry will start from the left side and flows to the right. If the text is so long that it exceeds the width of the cell, it will be wrapped to the next line within the cell.

In many of the ChartDirector sample code, the legend box background and border is set to transparent, so you cannot see the real size of the legend box. If you set the legend box to have a non-transparent background (using Box.setBackground), you can see its actual size. The sample code "Bars with Marks" is an example with a horizontal legend box having a non-transparent background.

If your code configures the width of the legend box, then your code already knows the position and size of the legend box, and you can freely use BaseChart.addText to the top-left or top-right of the legend box. If the legend box size is automatically set up by ChartDirector, you may first call BaseChart.layoutLegend to ask ChartDirector to compute the legend box size, then use Box.getWidth to get its width. In this way, your code knows the position and size of the legend box, and can add text to its corners.

For the type mismatch error, to trouble-shoot the issue, I suggest you to separate the code to two parts:

Dim temp
temp = "Overall Satisfaction: " & col8

Set textbox = c.addText(70, 65, temp, "arialbd.ttf", 8)

If the error occurs in the line "Overall Satisfaction: " & col8, it means col8 is not a text string, and cannot be convert to a text string. You may want to verify what is col8 in this case (eg. is it an object or an array or something else)?

Regards
Peter Kwan

  Re: Add extra labels to percentage bar chart
Posted by Chris on Mar-21-2013 00:39
Thanks Peter

Informative as ever! I tried adding a data table, but not sure how you push the barchart
plot right to leave the table on the left (if I change the plot left position it just pushes the
overlapped table/chart to the right!

Thanks
Chris

  Re: Add extra labels to percentage bar chart
Posted by Peter Kwan on Mar-22-2013 00:41
Hi Chris,

I assume you are using a horizontal bar chart (with swapXY in effect), and the vertical axis labels are on the left side of the chart.

First, use Axis.makeLabelTable, like (in C#/Java):

CDMLTable table = c.xAxis().makeLabelTable();

Now the vertical axis labels on the left side should become a table with 1 column.

You can then add more columns to the table for your other information. For example:

table.insertCol(0);   //insert another column as the left most column
for (int i = 0; i < labels.Length; ++i)
    table.setText(0, i, "My Label " + i);   //set the text of the left mode column

If your chart has too little space on the left side for the additional column, you may move the plot area and the table to the right by increasing the plot area left coordinate (the first parameter in setPlotArea). You may want to also reduce the plot area width (to avoid the right side of the plot area to go outside the chart), or increase the chart width.

Hope this can help.

Regards
Peter Kwan

  Re: Add extra labels to percentage bar chart
Posted by Chris on Mar-22-2013 20:25
Hi Peter

I got a nice data table in place, then noticed that now the data in the table is the opposite
to the data in the percentage stacked bar chart.  So top row of table matches up with
bottom line of the chart and bottom of data table matches the top line of chart!

If I remove the data table it flips the chart back to what I would expect (based on the
column sorting I had at a SQL statement level.)  All of the data for the table and chart
comes from the same sql dataset.  Any thoughts?

thanks
Chris

  Re: Add extra labels to percentage bar chart
Posted by Peter Kwan on Mar-23-2013 00:27
Hi Chris,

Sorry, I forgot that by default, the labels flow from the "origin" (the bottom) to the top. This is the same no matter you are using tables or not. For example, if you use:

c.xAxis().setLabels(myLabels);

you should find that the first label is at the bottom. If then you add an additional line "c.xAxis().makeLabelTable();" to convert the labels to a table, the first label is still at the bottom.

So in adding custom cells to the table, you need to put the extra information in the cells starting from the bottom:

for (int i = 0; i < labels.Length; ++i)
    table.setText(0, labels.Length - i - 1, "My Label " + i);

Hope this can help.

Regards
Peter Kwan

  Re: Add extra labels to percentage bar chart
Posted by Chris on Mar-25-2013 14:12
Hi Peter

Knew it was going to be something daft like that, works a treat.

Thanks

Chris