You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by GitBox <gi...@apache.org> on 2022/09/14 08:07:11 UTC

[GitHub] [echarts] cnovelli opened a new issue, #17649: How to display sum stack bar in echarts with legend handling

cnovelli opened a new issue, #17649:
URL: https://github.com/apache/echarts/issues/17649

   ### What problem does this feature solve?
   
   What I need is to show the totals above each column and for the total to be recalculated as the legend is shown or hidden. What is the best practice to do this?
   
   Before:
   
   Before picture
   
   After:
   
   After picture
   
   In this code example the total is calculated through a bar below those that are generated through echart, what I want to achieve is that the total of the bar below is recalculated every time the legend is modified
   
   `let result = 0;
   let array = [];
   
   const series = [
       {
         name: 'Direct',
         type: 'bar',
         stack: 'total',
         label: {
           show: true
         },
         emphasis: {
           focus: 'series'
         },
         data: [320, 302, 301, 334, 390, 330, 320]
       },
       {
         name: 'Mail total',
         type: 'bar',
         stack: 'total',
         label: {
           show: true
         },
         emphasis: {
           focus: 'series'
         },
         data: [120, 132, 101, 134, 90, 230, 210]
       },
       {
         name: 'Affiliate total',
         type: 'bar',
         stack: 'total',
         label: {
           show: true
         },
         emphasis: {
           focus: 'series'
         },
         data: [220, 182, 191, 234, 290, 330, 310]
       },
       {
         name: 'Video total',
         type: 'bar',
         stack: 'total',
         label: {
           show: true
         },
         emphasis: {
           focus: 'series'
         },
         data: [150, 212, 201, 154, 190, 330, 410]
       },
       {
         name: 'Search Engine',
         type: 'bar',
         stack: 'total',
         label: {
           show: true
         },
         emphasis: {
           focus: 'series'
         },
         data: [820, 832, 901, 934, 1290, 1330, 1320]
       },
     ];
     
     sum()
   
   option = {
     tooltip: {
       trigger: 'axis',
       axisPointer: {
         // Use axis to trigger tooltip
         type: 'shadow', // 'shtotalow' as default; can also be 'line' or 'shtotalow'
         label:{
           formatter: function (params){
             for ( let i = 0; i < params.seriesData.length-1; i++){
               result += params.seriesData[i].value
             } 
             let resultFinal = params.value + " -------------------- total: " + result
             result = 0;
             return resultFinal;
           }
         }
       }
     },
         legend: {
           data: series.map(item => item.name),
       },
     grid: {
       left: '3%',
       right: '4%',
       bottom: '3%',
       containLabel: true
     },
     xAxis: {
       type: 'value'
     },
     yAxis: {
       type: 'category',
       data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
     },
     series: [
       {
         name: 'Direct',
         type: 'bar',
         stack: 'total',
         label: {
           show: true
         },
         emphasis: {
           focus: 'series'
         },
         data: [320, 302, 301, 334, 390, 330, 320]
       },
       {
         name: 'Mail total',
         type: 'bar',
         stack: 'total',
         label: {
           show: true
         },
         emphasis: {
           focus: 'series'
         },
         data: [120, 132, 101, 134, 90, 230, 210]
       },
       {
         name: 'Affiliate total',
         type: 'bar',
         stack: 'total',
         label: {
           show: true
         },
         emphasis: {
           focus: 'series'
         },
         data: [220, 182, 191, 234, 290, 330, 310]
       },
       {
         name: 'Video total',
         type: 'bar',
         stack: 'total',
         label: {
           show: true
         },
         emphasis: {
           focus: 'series'
         },
         data: [150, 212, 201, 154, 190, 330, 410]
       },
       {
         name: 'Search Engine',
         type: 'bar',
         stack: 'total',
         label: {
           show: true
         },
         emphasis: {
           focus: 'series'
         },
         data: [820, 832, 901, 934, 1290, 1330, 1320]
       },
       {
       
         name: ' A total of ',
         type: 'bar',
         tooltip: {
           show: false
         },
         stack: '',
         color: '#FFFFFF',
         label: {
           normal: {
             show: true,
             position: 'right'
           },
         },
         data: array,
         z: -1,
         barGap: '-100%',
       }
     ]
   };
   
   
   function sum(){
     for ( let z = 0; z < series[0].data.length; z++){
       for( let i = 0; i < series.length; i++){
       result += series[i].data[z];
     }
     array.push(result)
     result = 0;
     }
   }`
   
   ### What does the proposed API look like?
   
   the api should have a function to add the total of the data labels and that is modified by handling the legend


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


Re: [I] How to display sum stack bar in echarts with legend handling [echarts]

Posted by "helgasoft (via GitHub)" <gi...@apache.org>.
helgasoft commented on issue #17649:
URL: https://github.com/apache/echarts/issues/17649#issuecomment-2430708299

   see #18618 for partial solution without tooltip total


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


Re: [I] How to display sum stack bar in echarts with legend handling [echarts]

Posted by "github-actions[bot] (via GitHub) via commits" <co...@echarts.apache.org>.
github-actions[bot] closed issue #17649: How to display sum stack bar in echarts with legend handling
URL: https://github.com/apache/echarts/issues/17649


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


Re: [I] How to display sum stack bar in echarts with legend handling [echarts]

Posted by "Naik1994 (via GitHub)" <gi...@apache.org>.
Naik1994 commented on issue #17649:
URL: https://github.com/apache/echarts/issues/17649#issuecomment-2159893437

   Hi Team,
   
   Is there any update on this feature request?
   
   Will it be picked up or included in any upcoming feature releases? This functionality is crucial for our use case, and the current custom handling does not work correctly when some legends are unselected, as the values do not update dynamically.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


Re: [I] How to display sum stack bar in echarts with legend handling [echarts]

Posted by "DMOAbove (via GitHub)" <gi...@apache.org>.
DMOAbove commented on issue #17649:
URL: https://github.com/apache/echarts/issues/17649#issuecomment-1803685105

   > liunanchenFYJJ
   
   Having the same issue, the way I am thinking to bypass that yAxis issue is to put the data not with the sum but with an index [0, 1, 2, 3, 4, 5] and after that I can use the formatter(params) and return the sum data array like this sumData[params.value] , params-value will be the index array, so we can access each value. In your case the graph will go to 15 only, since the biggest index number is 5.
   
   Best regards
   
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


Re: [I] How to display sum stack bar in echarts with legend handling [echarts]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #17649:
URL: https://github.com/apache/echarts/issues/17649#issuecomment-6375568969

   This issue has been automatically marked as stale because it did not have recent activity. It will be closed in 7 days if no further activity occurs. If you wish not to mark it as stale, please leave a comment in this issue.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


Re: [I] How to display sum stack bar in echarts with legend handling [echarts]

Posted by "github-actions[bot] (via GitHub) via commits" <co...@echarts.apache.org>.
github-actions[bot] commented on issue #17649:
URL: https://github.com/apache/echarts/issues/17649#issuecomment-6549136028

   This issue has been automatically closed because it did not have recent activity. If this remains to be a problem with the latest version of Apache ECharts, please open a new issue and link this to it. Thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [echarts] liunanchenFYJJ commented on issue #17649: How to display sum stack bar in echarts with legend handling

Posted by GitBox <gi...@apache.org>.
liunanchenFYJJ commented on issue #17649:
URL: https://github.com/apache/echarts/issues/17649#issuecomment-1305212194

   > You can stack another bar series with transparent background and set label position to be `'insideBottom'`.
   
   this will double the length of Value-Axis. how to solve this problem?
   ![21667807708_ pic](https://user-images.githubusercontent.com/23701496/200255655-5e40915c-b4c3-4d7f-a1b5-00735b0d3181.jpg)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [echarts] cnovelli commented on issue #17649: How to display sum stack bar in echarts with legend handling

Posted by GitBox <gi...@apache.org>.
cnovelli commented on issue #17649:
URL: https://github.com/apache/echarts/issues/17649#issuecomment-1247783540

   > You can stack another bar series with transparent background and set label position to be `'insideBottom'`.
   
   This does not solve the problem that I have of managing the legend so that the total is recalculated


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [echarts] cnovelli commented on issue #17649: How to display sum stack bar in echarts with legend handling

Posted by GitBox <gi...@apache.org>.
cnovelli commented on issue #17649:
URL: https://github.com/apache/echarts/issues/17649#issuecomment-1247775546

   > Puede apilar otra serie de barras con fondo transparente y establecer la posición de la etiqueta para que sea `'insideBottom'`.
   
   This does not solve the problem that I have of managing the legend so that the total is recalculated


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [echarts] Ovilia commented on issue #17649: How to display sum stack bar in echarts with legend handling

Posted by GitBox <gi...@apache.org>.
Ovilia commented on issue #17649:
URL: https://github.com/apache/echarts/issues/17649#issuecomment-1253281243

   I don't understand how legend is relevant here. Do you meed an image to further illustrate?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [echarts] Ovilia commented on issue #17649: How to display sum stack bar in echarts with legend handling

Posted by GitBox <gi...@apache.org>.
Ovilia commented on issue #17649:
URL: https://github.com/apache/echarts/issues/17649#issuecomment-1247766437

   You can stack another bar series with transparent background and set label position to be `'insideBottom'`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


Re: [I] How to display sum stack bar in echarts with legend handling [echarts]

Posted by "alearrigo (via GitHub)" <gi...@apache.org>.
alearrigo commented on issue #17649:
URL: https://github.com/apache/echarts/issues/17649#issuecomment-2429673773

   Hi, any updates on this feature?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org