How to change the Y-Axis to show $ in graph

2019-07-29 23:33发布

I want to see dollar sign along with the Y-Axis scale data. I am using ChartJS Version 2.1.0 for rendering graph. I looked into this LINK but I could not understand. I know I need to change my ScaleLabel but I am not able to do so. Kindly guide me. so scale 2000 should show as $2000 Below is what I have till now.

define(['backbone'], function(Backbone) {
  var firstSubViewModel = Backbone.View.extend({
    template: _.template($('#myChart-template').html()),
    render: function() {
      $(this.el).html(this.template());
      var ctx = $(this.el).find('#lineChart')[0];
      var lineChart = new Chart(ctx, {
        type: 'line',
        data: {
          labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
          datasets: {
            label: "This Year",
            data: this.model.attributes.incThisYear
          }
        },
        options: {
          scales: {
            yAxes: [{
              scaleLabel: {
                display: true
              }
            }]
          }
        }
      });
    },
    initialize: function() {
      this.render();
    }
  });
  return firstSubViewModel;
});

Image:

enter image description here

EDIT

My options looks like this now:

  options: {
          scales: {
            yAxes: [{

              scaleLabel: function (incValue){ return '$ '+ incValue.value; }
            }]
          }
        }

1条回答
霸刀☆藐视天下
2楼-- · 2019-07-29 23:48

My suggestion is to add the following to the options:

scaleLabel: function (incValue){ return '$ '+ incValue.value; } 

It is working in this example

查看更多
登录 后发表回答