Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sum method not giving correct result #6

Open
NeeruAR opened this issue Jun 7, 2022 · 2 comments
Open

Sum method not giving correct result #6

NeeruAR opened this issue Jun 7, 2022 · 2 comments

Comments

@NeeruAR
Copy link

NeeruAR commented Jun 7, 2022

I am trying to use the aggregate sum method in echart but it is not giving proper result.
For the month of Mar output should be 1000, for April 210 and for August 148.

$.when(
  $.getScript(
    'https://fastly.jsdelivr.net/npm/echarts-simple-transform/dist/ecSimpleTransform.min.js'  )
).done(function (res) {
  run(res);
});

function run() {
  echarts.registerTransform(ecSimpleTransform.aggregate);
  option = {
	    dataset: [
	      {
	        id: 'raw',
	        dimensions: ['billAmount', 'billMonth'],
	        source: [
          {
            billMonth: 'Mar',
            billAmount: '400'
          },
          {
            billMonth: 'Mar',
            billAmount: '100'
          },
          {
            billMonth: 'Mar',
            billAmount: '500'
          },
          {
            billMonth: 'April',
            billAmount: '10'
          },
          {
            billMonth: 'April',
            billAmount: '200'
          },
          {
            billMonth: 'August',
            billAmount: '148'
          }
        ]
      },
      {
        id: 'month',
        fromDatasetId: 'raw',
        transform: [
          {
            type: 'filter',
            config: {
              dimension: 'billMonth',
              eq: 'Mar'
            }
          }
        ]
      },
      {
	       id: 'bill_sum',
        fromDatasetId: 'raw',
        transform: [
          {
            type: 'ecSimpleTransform:aggregate',
            config: {
              resultDimensions: [
                { from: 'billAmount', method: 'sum' },
                { from: 'billMonth' }
              ],
              groupBy: 'billMonth'
            }
          }
        ]
      },
   ],
    title: {
      text: 'SUM OF BILL'
    },
    tooltip: {
      trigger: 'axis',
      confine: true
    },
    xAxis: {
      name: 'billMonth',
      nameLocation: 'middle',
      nameGap: 30,
      scale: true,
      type: 'category',
      boundaryGap: true,
      axisLabel: {
        interval: 0,
        fontSize: 12,
        rotate: 15
      }
    },
    yAxis: {
      type: 'value',
      axisLabel: {
        interval: 0,
        fontSize: 12,
        rotate: 7
      }
    },
    grid: {
      bottom: 100
    },
    legend: {
      width: 330,
      type: 'scroll'
    },
    series: [
      {
        type: 'bar',
        datasetId: 'bill_sum',
        name: 'billamount',
        encode: {
          x: 'billMonth',
          y: 'billAmount'
        },
        color: 'red'
      }
    ] 
   };
    myChart.setOption(option);
}

Error Output :
image

@svedova
Copy link

svedova commented Jun 8, 2023

In my case it always skips the first row.

@helgasoft
Copy link

duplicate of #1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants