@@ -27,6 +27,7 @@ public class CampaignDashboardDiagramComponent extends VerticalLayout {
2727 private final List <Object > axisKeys = new ArrayList <Object >();
2828 private final Map <Object , String > axisCaptions = new HashMap <Object , String >();
2929 private final Map <Object , Double > totalValues ;
30+ private boolean showPercentage = true ;
3031
3132 private final HighChart campaignColumnChart ;
3233
@@ -67,7 +68,8 @@ public CampaignDashboardDiagramComponent(
6768 buildDiagramChart (diagramDefinition .getDiagramCaption ());
6869 }
6970
70- private void buildDiagramChart (String title ) {
71+ public void buildDiagramChart (String title ) {
72+ this .showPercentage = !showPercentage ;
7173 final StringBuilder hcjs = new StringBuilder ();
7274
7375 //@formatter:off
@@ -81,9 +83,24 @@ private void buildDiagramChart(String title) {
8183 + "},"
8284 + "credits:{ enabled: false },"
8385 + "exporting:{ "
84- + " enabled: true,"
85- + " buttons:{ contextButton:{ theme:{ fill: 'transparent' } } }"
86- + "},"
86+ + " enabled: true," );
87+ //@formatter:on
88+
89+ if (totalValues != null ) {
90+ hcjs .append (
91+ " menuItemDefinitions: { togglePercentages: { onclick: function() { window.changeDiagramState_" + diagramDefinition .getDiagramId ()
92+ + "(); }, text: '" + (showPercentage ? "Show total values" : "Show percentages" ) + "' } }, " );
93+ }
94+
95+ hcjs .append (" buttons:{ contextButton:{ theme:{ fill: 'transparent' }" );
96+
97+ if (totalValues != null ) {
98+ hcjs .append (
99+ ", menuItems: ['viewFullscreen', 'printChart', 'separator', 'downloadPNG', 'downloadJPEG', 'downloadPDF', 'downloadSVG', 'separator', 'downloadCSV', 'downloadXLS', 'viewData', 'separator', 'togglePercentages']" );
100+ }
101+
102+ //@formatter:off
103+ hcjs .append ("} } },"
87104 + "legend: { backgroundColor: 'transparent', margin: 30 },"
88105 + "colors: ['#4472C4', '#ED7D31', '#A5A5A5', '#FFC000', '#5B9BD5', '#70AD47', '#FF0000', '#6691C4','#ffba08','#519e8a','#ed254e','#39a0ed','#FF8C00','#344055','#D36135','#82d173'],"
89106 + "title:{ text: '" + title + "', style: { fontSize: '15px' } }," );
@@ -107,7 +124,7 @@ private void buildDiagramChart(String title) {
107124
108125 //@formatter:off
109126 hcjs .append ("yAxis: { min: 0, title: { text: ''}" );
110- if (totalValues != null ) {
127+ if (showPercentage && totalValues != null ) {
111128 hcjs .append (", max: 100, " );
112129 }
113130 if (stackMap .size () > 1 ) {
@@ -119,13 +136,13 @@ private void buildDiagramChart(String title) {
119136
120137 // series
121138
122- if (stackMap .size () > 0 || totalValues != null ) {
139+ if (stackMap .size () > 0 || ( showPercentage && totalValues != null ) ) {
123140 hcjs .append ("plotOptions: {" );
124141
125142 if (stackMap .size () > 0 ) {
126143 hcjs .append ("column: { stacking: 'normal'}" );
127144 }
128- if (totalValues != null ) {
145+ if (showPercentage && totalValues != null ) {
129146 hcjs .append (stackMap .size () > 0 ? ", " : "" ).append ("series: { dataLabels: { enabled: true, format: '{y} %'}}" );
130147 }
131148
@@ -145,7 +162,7 @@ private void buildDiagramChart(String title) {
145162 hcjs .append ("{ name:'" ).append (fieldName ).append ("', data: [" );
146163 for (Object axisKey : axisKeys ) {
147164 if (seriesData .containsKey (axisKey )) {
148- if (totalValues != null ) {
165+ if (showPercentage && totalValues != null ) {
149166 double totalValue = totalValues .get (seriesData .get (axisKey ).getGroupingKey ());
150167 if (totalValue > 0 ) {
151168 hcjs .append (
@@ -174,4 +191,5 @@ private void buildDiagramChart(String title) {
174191
175192 campaignColumnChart .setHcjs (hcjs .toString ());
176193 }
194+
177195}
0 commit comments