如何更改Y轴在图中显示$ [英] How to change the Y-Axis to show $ in graph

查看:132
本文介绍了如何更改Y轴在图中显示$的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想看到美元符号和Y轴缩放数据。我使用ChartJS版本2.1.0渲染图。我查看了此



EDIT



我现在的选项如下:

 选项:{
scales:{
yAxes: [{

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


解决方案

我的建议是添加以下选项:

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

它在此示例


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:

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

这篇关于如何更改Y轴在图中显示$的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆