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

Message ListMessage List     Post MessagePost Message

  Data labels for bar chart sometimes don't show up
Posted by Wes Garrison on Nov-27-2014 04:20
Here's what I'm seeing:
http://cl.ly/image/1w1M123H1W1w

Some of my data points don't have data labels.

Relevant code:

    layer = c.addBarLayer2()
    layer.setBarGap(SPACE_BETWEEN_BARS, ChartDirector::TouchBar)
    values = method_that_returns_values_array()
    dataset = layer.addDataSet(values)

    # attempt #1
    layer.setDataLabelStyle()

    # attempt #2
    values.each_with_index do |value, index|
      label_box = layer.addCustomDataLabel(0, index, "X" )
    end


For attempt #1, I do get the correct value shown (for the ones that it appears on). I do
get the textbox back and can move the label around, I just removed that from the code to
make it clearer.  Formatting decimals places and such works.

I tried replacing the numeric value with "X" to see if it was something to do with the value
(I do have some NoValue elements).

Any guidance would be appreciated.

  Re: Data labels for bar chart sometimes don't show up
Posted by Wes Garrison on Nov-27-2014 04:22
Ruby, version 5.1.1, on Mac OS X Mavericks.

  Re: Data labels for bar chart sometimes don't show up
Posted by Peter Kwan on Nov-27-2014 23:32
Hi Wes,

The issue is because "data labels" are supposed to be inside the bar segments. This type of
label is commonly used for stacked bar charts to label the bar segments. ChartDirector will
hide the label if the bar segment is "too short" so that there is insufficient space for the
labels. The definition for "too short" is configurable using BarLayer.setMinLabelSize.

There is another kind of label called the "aggregate label" which will appear outside the bar
at the "data end" of the bars (which is the top of the bars for positive bars, and the bottom
of the bars for negative bars).

For your case, your code is using "data labels", so it is automatically hidden for small bar
segments, even if your code subsequently move the labels to somewhere else. To solve the
problem, there are two methods:

(a) Use aggregate labels, which is by default outside the bars. For example:

layer.setAggregateLabelStyle()

(b) Use BarLayer.setMinLabelSize to set the "too short" to be 0, which means the data
labels will always be displayed, even if the bar is zero in height.

layer.setMinLabelSize(0)

Hope this can help.

Regards
Peter Kwan