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

Message ListMessage List     Post MessagePost Message

  Displaying the aggrate value above the bar in a tooltip
Posted by Franck Barbenoire on Aug-11-2017 23:29
Hi support,

As stated in the title, I'd like to know how to display the "value" (in fact the custom string "<1", not a value) above the bar (through an aggregate value) in the tooltip. I have only one data in the bar.

I haven't found anything that could help in the "Parameter Substitution and Formatting" page of the documentation. I've tried accValue, but it relies on the value of the data bar, not the custom string displayed above it.

Thank you for your answer

None: your response will not be read until 16th August :)

  Re: Displaying the aggrate value above the bar in a tooltip
Posted by Peter Kwan on Aug-12-2017 00:30
Hi Franck,

If you want to display "<1", I think you just enter it as is, like (in C#):

layer.setAggregateLabelFormat("<1");

If you have many bars, and you want a different custom string to be displayed on each bar, you can create an array of text strings contain the custom strings for your bars, then add them as a custom field, and display the custom field on the bars.

layer.addExtraField(anArrayOfTextStrings);

// display the custom field on the bars
layer.setAggregateLabelFormat("{field0}");

Hope this can help.

Regards
Peter Kwan

  Re: Displaying the aggrate value above the bar in a tooltip
Posted by Peter Kwan on Aug-15-2017 18:33
Hi Franck,

I read your message again, and I realize you are referring to the "tooltip" label. For the tooltip label, you just need to put the "{field0}" in your tooltip to refer to the custom label.

Hope this can help.

Regards
Peter Kwan

  Re: Displaying the aggrate value above the bar in a tooltip
Posted by Franck Barbenoire on Aug-16-2017 22:38
Hello Peter,

Thank you for your answer.

It solved partially my problem : for bars of single values and bars of many stacked values, it solves the problem. I can have a custom text above the bars, and the tooltip contains the same text.

But for many values, displayed side by side, the extra data applies to all the bars in each group and not to each bar individually. The problem is :
- how to have custom values ABOVE (I mean not inside !) bars in this kind of graph ?
- how to have a tooltip that reflect the value above each bar whether bars belong to the same group or not ?

In order to give you enough informations, here is some technical information about the way we generate the later graph (Python code) :

from pychartdir import Side
img = xyChart(0, 0)
layer = img.addBarLayer2(Side)
for stack, detail in zip(stacks, details):
    layer.addDataSet(stack, -1, details)

The loop variables (stack and detail) will look like this (in the example 24 bars grouped in 8 groups, which will give 24 different colors) :

- iteration #1 :
stack =(1.094, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
detail = "detail 1"

- iteration #2 :
stack =(0.11, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
detail = "detail 2"

- iteration #3 :
stack =- iteration #2 :
stack =(1.7e+308, 0.06, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
detail = "detail 3"

...

- iteration #24
stack =(1.7e+308,1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 0.513)
detail = "detail 24"

There will have 2 bars side by side in the first group (1.094 and 0.11), 1 bar in the second (0.06),...

The purpose is to display "1" above the first bar (value rounded to the nearest unit), "<1" above the second and the third, the tooltip containing the same string.

Thanks.

Franck

  Re: Displaying the aggrate value above the bar in a tooltip
Posted by Peter Kwan on Aug-17-2017 00:18
Hi Franck,

From your data, there are 4 arrays, each with 8 elements, representing 32 bars in total. It happens most of the values are NoValue.

For the custom tooltips, please prepare 4 arrays, each with 8 text strings, with a total of 32 strings for 32 bars. You can use an empty strings for NoValue bars.

The code is then:

layer.addExtraField(toolTipArrayForIteration1)
layer.addExtraField(toolTipArrayForIteration2)
layer.addExtraField(toolTipArrayForIteration3)
layer.addExtraField(toolTipArrayForIteration4)

In the tooltip, you can use {dsdiField0} to represent the tooltip. The "dids" means the tooltip is indexed by the data item (di) number (array index), and also by the data set (ds) number.

Hope this can help.

Regards
Peter Kwan

  Re: Displaying the aggrate value above the bar in a tooltip
Posted by Franck Barbenoire on Aug-17-2017 22:36
Hello Peter,

Thanks for your answer.

It almost works now, the tooltips are OK for each bar. The remaining issue is to display custom strings above the bars.

I tried layer.setDataLabelFormat("{dsdiField0}"), but it display the string inside the bars, not above.

I also tried  layer.setAggregateLabelFormat("{dsdiField0}") but it still displays the value above the bars.

Thanks,

Franck

  Re: Displaying the aggrate value above the bar in a tooltip
Posted by Peter Kwan on Aug-18-2017 01:42
Hi Franck,

There are two methods:

(a) Just shift the label upwards to move them outside the bar.

layer.setDataLabelFormat("<*yoffset=15*>{dsdiField0}")

(b) Use Layer.addCustomGroupLabel:

allToolTips = [toolTipArrayForIteration1, toolTipArrayForIteration2, toolTipArrayForIteration3, toolTipArrayForIteration4]
for n in range(len(allToolTips)) :
     for m in range(len(allToolTips[n])) :
          layer.addCustomGroupLabel(n, m, allToolTips[n][m], "arial.ttf", 8, 0x000000)


Hope this can help.

Regards
Peter Kwan

  Re: Displaying the aggrate value above the bar in a tooltip
Posted by Franck Barbenoire on Aug-18-2017 16:26
Hi Peter,

It works but there's a last issue : make disappear the data value so that I see only the custom string above the graph.

Thanks,
Franck

  Re: Displaying the aggrate value above the bar in a tooltip
Posted by Franck Barbenoire on Aug-18-2017 17:31
Hi Peter,

I forgot to tell you that I have chosen the (a) solution.

The function that controls the value above the bar is layer.setAggregateLabelFormat().

I can make disappear the value if I give " " (single space character) to setAggregateLabelFormat(). If I give "" (empty string), it display the value by default.

Is there a better method than " " for making disappear the value ?

Thanks,

Franck

  Re: Displaying the aggrate value above the bar in a tooltip
Posted by Peter Kwan on Aug-18-2017 20:45
Hi Franck,

I am not too sure the exact code you are using.

If you are using method (a), it uses only Layer.setDataLabelFormat. It does not use Layer.setAggregateLabelFormat. If the code does not have Layer.setAggregateLabelFormat or Layer.setAggregateLabelStyle, there should be no automatic aggregate label on the bars.

If you add Layer.setAggregateLabelFormat to the code, ChartDirector assumes you want the label, in which case an empty string will be assumed to mean the default label format. You can remove the  Layer.setAggregateLabelFormat if no label is needed.

Regards
Peter Kwan

  Re: Displaying the aggrate value above the bar in a tooltip
Posted by Franck Barbenoire on Aug-18-2017 21:53
Attachments:
Hello Peter,

You are absolutely right : a setAggregateLabelStyle("") was on the way. I removed it along with the setAggregateLabelFormat(" ") and no value is showing, now. Thanks.

A other strange thing happens : the extra field does not show above "certain" bars. The only thing in common that I see between these is that they are very small in size. I attach the graph to the post (I pasted a cursor as the print screen didn't copy it).

Its difficult to understand this as the tooltips show correctly when the cursor is put over all the bars. This demonstrates that an extra field is attached to all the bars. I used layer.setDataLabelFormat so that all bars in the graph should behave the same way.

Here is the code :

def getImg():
    img = XYChar(0,0)
    img.setPlotArea(...)
    layer = getLayer(data, details)
    legend = img.addLengend2(...)
    img.addTitle(...)
   # various operation on the axis
   img.setBackground(Transparent, Transparent)
   layer.setBarWidth(...)
   return img

def getLayer(data, details):
        layer = img.addBarLayer2(Side)
        data = list(data)
        for stack, detail in zip(data, details):
                layer.addDataSet(stack, -1, detail)
        layer.setDataLabelStyle("")
        layer.setDataLabelFormat("<*yoffset=+15*>{dsdiField0}")
        for stack in data:
            print(stack)
            tooltips = [""] * len(stack)
            for i, d in enumerate(stack):
                if d == NoValue:
                    continue
                elif d < 1:
                    tooltips[i] = "<1"
                else:
                    tooltips[i] = str(int(d))
           print(tooltips)
           layer.addExtraField(tooltips)
        return layer

And here is the result of the print statements :

(0.894, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['<1', '', '', '', '', '', '', '']
(0.11, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['<1', '', '', '', '', '', '', '']
(0.088, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['<1', '', '', '', '', '', '', '']
(1.7e+308, 0.06, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '<1', '', '', '', '', '', '']
(1.7e+308, 1.7e+308, 0.035, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '<1', '', '', '', '', '']
(1.7e+308, 1.7e+308, 1.7e+308, 0.021, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '', '<1', '', '', '', '']
(0.016, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['<1', '', '', '', '', '', '', '']
(1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 0.013, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '', '', '<1', '', '', '']
(1.7e+308, 0.009, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '<1', '', '', '', '', '', '']
(1.7e+308, 0.005, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '<1', '', '', '', '', '', '']
(1.7e+308, 1.7e+308, 0.005, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '<1', '', '', '', '', '']
(1.7e+308, 1.7e+308, 1.7e+308, 0.005, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '', '<1', '', '', '', '']
(1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 0.004, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '', '', '<1', '', '', '']
(1.7e+308, 1.7e+308, 1.7e+308, 0.003, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '', '<1', '', '', '', '']
(1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 0.003, 1.7e+308, 1.7e+308)
['', '', '', '', '', '<1', '', '']
(1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 0.002, 1.7e+308)
['', '', '', '', '', '', '<1', '']
(1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 0.001, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '', '', '<1', '', '', '']
(1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 0.001)
['', '', '', '', '', '', '', '<1']
(1.7e+308, 1.7e+308, 1.7e+308, 0.001, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '', '<1', '', '', '', '']
(0.001, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['<1', '', '', '', '', '', '', '']
(1.7e+308, 0.001, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '<1', '', '', '', '', '', '']
(0.001, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['<1', '', '', '', '', '', '', '']
(1.7e+308, 1.7e+308, 0.001, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '<1', '', '', '', '', '']
(1.7e+308, 1.7e+308, 0.001, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '<1', '', '', '', '', '']
(0.894, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['<1', '', '', '', '', '', '', '']
(0.11, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['<1', '', '', '', '', '', '', '']
(0.088, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['<1', '', '', '', '', '', '', '']
(1.7e+308, 0.06, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '<1', '', '', '', '', '', '']
(1.7e+308, 1.7e+308, 0.035, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '<1', '', '', '', '', '']
(1.7e+308, 1.7e+308, 1.7e+308, 0.021, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '', '<1', '', '', '', '']
(0.016, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['<1', '', '', '', '', '', '', '']
(1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 0.013, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '', '', '<1', '', '', '']
(1.7e+308, 0.009, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '<1', '', '', '', '', '', '']
(1.7e+308, 0.005, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '<1', '', '', '', '', '', '']
(1.7e+308, 1.7e+308, 0.005, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '<1', '', '', '', '', '']
(1.7e+308, 1.7e+308, 1.7e+308, 0.005, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '', '<1', '', '', '', '']
(1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 0.004, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '', '', '<1', '', '', '']
(1.7e+308, 1.7e+308, 1.7e+308, 0.003, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '', '<1', '', '', '', '']
(1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 0.003, 1.7e+308, 1.7e+308)
['', '', '', '', '', '<1', '', '']
(1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 0.002, 1.7e+308)
['', '', '', '', '', '', '<1', '']
(1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 0.001, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '', '', '<1', '', '', '']
(1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 0.001)
['', '', '', '', '', '', '', '<1']
(1.7e+308, 1.7e+308, 1.7e+308, 0.001, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '', '<1', '', '', '', '']
(0.001, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['<1', '', '', '', '', '', '', '']
(1.7e+308, 0.001, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '<1', '', '', '', '', '', '']
(0.001, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['<1', '', '', '', '', '', '', '']
(1.7e+308, 1.7e+308, 0.001, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '<1', '', '', '', '', '']
(1.7e+308, 1.7e+308, 0.001, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308, 1.7e+308)
['', '', '<1', '', '', '', '', '']

Thanks again, you are very helpful !

Franck
graph.png

  Re: Displaying the aggrate value above the bar in a tooltip
Posted by Peter Kwan on Aug-19-2017 21:40
Hi Franck,

I see. Please add the line:

layer.setMinLabelSize(0)

The issue is because ChartDirector still thinks the data label is inside the bar, even it has already been moved outside. For a data label, by default, ChartDirector will only display it if there is the bar is tall enough for the label. The setMinLabelSize(0) tells ChartDirector to display the label even if the bar height is 0.

Hope this can help.

Regards
Peter Kwan

  Re: Displaying the aggrate value above the bar in a tooltip
Posted by Franck Barbenoire on Aug-21-2017 16:04
Hello Peter,

no more issue now :)

Thank you for your help :)

Franck