简体   繁体   English

如何更改Y轴以显示$ in graph

[英]How to change the Y-Axis to show $ in graph

I want to see dollar sign along with the Y-Axis scale data. 我希望看到美元符号和Y轴比例数据。 I am using ChartJS Version 2.1.0 for rendering graph. 我使用ChartJS版本2.1.0来渲染图形。 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. 我知道我需要更改我的ScaleLabel,但我无法这样做。 Kindly guide me. 请指导我。 so scale 2000 should show as $2000 Below is what I have till now. 所以2000 should show as $2000规模2000 should show as $2000以下是我现在所拥有的。

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: 图片:

在此输入图像描述

EDIT 编辑

My options looks like this now: 我的选项现在看起来像这样:

  options: {
          scales: {
            yAxes: [{

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

My suggestion is to add the following to the options: 我的建议是在选项中添加以下内容:

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

It is working in this example 它正在这个例子中工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM