Home » Javascript » Display Empty Data if all data values are zero in piechart Chartjs

Display Empty Data if all data values are zero in piechart Chartjs

Posted by: admin June 30, 2018 Leave a comment

Questions:

While displaying pie chart, I encounter scenarios when all the values for the data sets will be zero. Right now, when this occurs the piechart is not manifested. Instead I want to display a text as Empty Data for such case. My backbone code is as follows. Ay help would be appreciated!

ctx = $(@el).find('#active-goals-status canvas#pie-chartcanvas')[0]
ctx.height = 100%
labels = []
values = []

$.each @status_model.get('goal_status'),(status, value)->
  labels.push(status)
  values.push(value)

myPieChart = new ChartNew ctx,
  type: 'pie',
  data:
    labels: labels
    datasets: [
      backgroundColor: ['#DCDCDC','#FF0000','#00FF00','#FFFF00']
      data: values
    ]
  options:
    responsive: true
    title:
      display: true,
      text: ECL.t('goals_status_upcase', {default_value: 'GOAL 
            STATUS'})
      position: 'bottom'
      fontSize: 12
      fontColor: '#999'
      fontStyle: 'normal'
    legend:
      display: false
    layout: 
      padding: 
        left: 0
        right: 0
      margin:
        left: 0
        right: 0
Answers: