Focal Point
[SOLVED] Data Labels with Series Label and Data Value on Stacked Bar

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/6267096096

August 17, 2018, 07:27 PM
Matthew S
[SOLVED] Data Labels with Series Label and Data Value on Stacked Bar
I've been tasked with making stacked bar charts that will include both the series label and the data value on the chart as a data label.
So for the CAR example below, instead of just having the sales amount for each series it would also have the country like: "JAPAN: 78,030".
This seems like a very simple task but I can't seem to find a way to do it. I can either display the data value or the series value but not both.

GRAPH FILE CAR
SUM CAR.BODY.SALES
BY CAR.ORIGIN.COUNTRY
BY CAR.BODY.BODYTYPE
WHERE CAR.BODY.BODYTYPE EQ 'SEDAN';
WHERE CAR.ORIGIN.COUNTRY NE 'ITALY';
ON GRAPH PCHOLD FORMAT JSCHART
ON GRAPH SET VZERO OFF
ON GRAPH SET GRWIDTH 1
ON GRAPH SET AUTOFIT ON
ON GRAPH SET UNITS &WF_STYLE_UNITS
ON GRAPH SET HAXIS &WF_STYLE_WIDTH
ON GRAPH SET VAXIS &WF_STYLE_HEIGHT
ON GRAPH SET LOOKGRAPH BAR
ON GRAPH SET AUTOFIT ON
ON GRAPH SET STYLE *
*GRAPH_SCRIPT
setPieDepth(0);
setPieTilt(0);
setDepthRadius(0);
setPlace(true);
setCurveFitEquationDisplay(false);
*END
INCLUDE=IBFS:/FILE/IBI_HTML_DIR/javaassist/intl/EN/ENIADefault_combine.sty,$
TYPE=REPORT, TITLETEXT=&WF_TITLE.QUOTEDSTRING, $
TYPE=DATA, COLUMN=N1, BUCKET=color, $
TYPE=DATA, COLUMN=N2, BUCKET=x-axis, $
TYPE=DATA, COLUMN=N3, BUCKET=y-axis, $
*GRAPH_SCRIPT
setReportParsingErrors(false);
setSelectionEnableMove(false);
setDataTextPosition(4);
setDataTextDisplay(true);
setDisplay(getLegendArea(),false);
*GRAPH_JS_FINAL
"pieProperties": {
    "holeSize": "0%"
},
"blaProperties": {
    "seriesLayout": "stacked"
},
"agnosticSettings": {
    "chartTypeFullName": "Bar_Stacked"
}
*END
ENDSTYLE
END
-RUN  

This message has been edited. Last edited by: Matthew S,


WebFocus 8207
Windows 10
Excel, HTML
August 20, 2018, 07:55 AM
MartinY
Is that what you're looking for ?
GRAPH FILE CAR
SUM SALES
    COMPUTE TT1      /A30V = 'My Tooltip';
    COMPUTE TT2      /A30V = COUNTRY || ' : ' | FPRINT(SALES, 'D8', 'A10');
BY COUNTRY
BY BODYTYPE
WHERE BODYTYPE EQ 'SEDAN';
WHERE COUNTRY NE 'ITALY';
ON GRAPH PCHOLD FORMAT JSCHART
ON GRAPH SET VZERO OFF
ON GRAPH SET GRWIDTH 1
ON GRAPH SET AUTOFIT ON
ON GRAPH SET UNITS PIXELS
ON GRAPH SET HAXIS 700
ON GRAPH SET VAXIS 400
ON GRAPH SET LOOKGRAPH BAR
ON GRAPH SET AUTOFIT ON
ON GRAPH SET STYLE *
*GRAPH_SCRIPT
setPieDepth(0);
setPieTilt(0);
setDepthRadius(0);
setPlace(true);
setCurveFitEquationDisplay(false);
*END
INCLUDE=IBFS:/FILE/IBI_HTML_DIR/javaassist/intl/EN/ENIADefault_combine.sty,$
TYPE=REPORT, TITLETEXT=&WF_TITLE.QUOTEDSTRING, $
TYPE=DATA, COLUMN=N1, BUCKET=color, $
TYPE=DATA, COLUMN=N2, BUCKET=x-axis, $
TYPE=DATA, COLUMN=N3, BUCKET=y-axis, $
TYPE=DATA, COLUMN=TT1,     BUCKET=tooltip, $
TYPE=DATA, COLUMN=TT2,     BUCKET=tooltip, $
*GRAPH_JS_FINAL
series: [ {"series": 'reset', "tooltip": '{{tooltip1}}<br>{{tooltip2}}'} ],
htmlToolTip: {enable: true, snap: false }
*END
*GRAPH_SCRIPT
setReportParsingErrors(false);
setSelectionEnableMove(false);
setDataTextPosition(4);
setDataTextDisplay(true);
setDisplay(getLegendArea(),false);
*GRAPH_JS_FINAL
"pieProperties": {
    "holeSize": "0%"
},
"blaProperties": {
    "seriesLayout": "stacked"
},
"agnosticSettings": {
    "chartTypeFullName": "Bar_Stacked"
}
*END
ENDSTYLE
END
-RUN

You can add as many as you want. Each tooltip will be on its own line.


WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
August 20, 2018, 08:30 AM
Tony A
In case you meant the data labels and not tooltips, here is another slant. This method can be found in the JSCHART manual (page 135 of the copy that I have) within chapter "4 Chart-Wide properties" under "Using a Callback Function to Format Data Labels".

My suggestion is to download a copy of the PDF for reference.

GRAPH FILE CAR
SUM SALES
    COMPUTE TT1/A30V = COUNTRY || ' : ' | FPRINT(SALES, 'D8', 'A10');
BY COUNTRY
BY BODYTYPE
WHERE BODYTYPE EQ 'SEDAN';
WHERE COUNTRY NE 'ITALY';
ON GRAPH PCHOLD FORMAT JSCHART
ON GRAPH SET VZERO OFF
ON GRAPH SET GRWIDTH 1
ON GRAPH SET AUTOFIT ON
ON GRAPH SET UNITS PIXELS
ON GRAPH SET HAXIS 700
ON GRAPH SET VAXIS 400
ON GRAPH SET LOOKGRAPH BAR
ON GRAPH SET AUTOFIT ON
ON GRAPH SET STYLE *
*GRAPH_SCRIPT
setPieDepth(0);
setPieTilt(0);
setDepthRadius(0);
setPlace(true);
setCurveFitEquationDisplay(false);
*END
INCLUDE=IBFS:/FILE/IBI_HTML_DIR/javaassist/intl/EN/ENIADefault_combine.sty,$
TYPE=REPORT, TITLETEXT=&WF_TITLE.QUOTEDSTRING, $
TYPE=DATA, COLUMN=N1, BUCKET=color, $
TYPE=DATA, COLUMN=N2, BUCKET=x-axis, $
TYPE=DATA, COLUMN=N3, BUCKET=y-axis, $
TYPE=DATA, COLUMN=TT1, BUCKET=tooltip, $
*GRAPH_JS_FINAL
dataLabels: {
    visible: true,
    position: 'bottom',
    formatCallback: function(d) {return d.tooltip1;}
},
htmlToolTip: {enable: true, snap: false }
*END
*GRAPH_SCRIPT
setReportParsingErrors(false);
setSelectionEnableMove(false);
setDisplay(getLegendArea(),false);
*GRAPH_JS_FINAL
"pieProperties": {
    "holeSize": "0%"
},
"blaProperties": {
    "seriesLayout": "stacked"
},
"agnosticSettings": {
    "chartTypeFullName": "Bar_Stacked"
}
*END
ENDSTYLE
END


T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
August 20, 2018, 08:54 AM
Matthew S
Tony A,

Yes, I did want it for data labels and not tooltips.
Thank you for your reply. This should work well.


WebFocus 8207
Windows 10
Excel, HTML
August 20, 2018, 09:36 AM
Doug
Nice works guys.
If you know me, I'll do / ask for more. So, What needs to be done to eliminate "'SALES:' and 'COUNTRY:' from displaying in the tooltip (on hover)? It's redundant information.
August 20, 2018, 09:41 AM
Tony A
I'd argue that the entire tooltips are redundant, especially if you capture the chart as an image and place within a PDF doc.

So I would use
htmlToolTip: {enabled: false}
and get rid of them completely.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
August 20, 2018, 04:59 PM
Matthew S
quote:
Originally posted by Doug:
Nice works guys.
If you know me, I'll do / ask for more. So, What needs to be done to eliminate "'SALES:' and 'COUNTRY:' from displaying in the tooltip (on hover)? It's redundant information.


I did turn off tooltips but if for some reason they needed to be kept you could do something like:
series: *GRAPH_JS_FINAL
"pieProperties": {
    "holeSize": "0%"
},
"blaProperties": {
    "seriesLayout": "stacked"
},
"agnosticSettings": {
    "chartTypeFullName": "Bar_Stacked"
},
dataLabels: {
    visible: true,
    position: 'bottom',
    formatCallback: function(d) {return d.tooltip1;}
},
htmlToolTip: {enable: true, snap: false },
series: [  {
"series": 'reset', "tooltip": '{{tooltip1}}'+'<br>'+'Why do you need a tooltip here?'
      }  ],
  

This message has been edited. Last edited by: Matthew S,


WebFocus 8207
Windows 10
Excel, HTML