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

时间:2016-08-31 18:19:54

标签: javascript backbone.js charts chart.js

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 个答案:

答案 0 :(得分:0)

我的建议是在选项中添加以下内容:

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

它正在使用此example

相关问题