本文介绍了在morris.js折线图中将整数看作y轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始在我的html页面中使用morris.js折线图。
有没有办法将y轴设置为只包含整数?
现在它显示十进制数字,但我的数据集只包含整数。

I have started using morris.js line chart in my html page.Is there a way to set the y-axis to only contain integers?Now it displays decimal numbers, but my data set only contains integers.

推荐答案

此功能由版本和配置如下:

This feature was added by this pull request about 25 days ago on the Github repository. It added the option gridIntegers that, by default, is set to false. It is still not merged to the main repository. Therefore, if you want to use it right now, you have to download this version and configure like following:

    Morris.Line({
      element: "mydiv",
      data: mydata,
      xkey: 'time',
      ykeys: ['value'],
      labels: ['Requisições'],
      gridIntegers: true,
      ymin: 0
    });

您是否看到 ymin 参数设置为 0 ?这是警告!当且仅当您设置自定义y-min和/或y-max边界时,y轴将仅使用整数。在我的情况下,这是可行的,因为我知道我的数据将不会显示低于0的值。因此,它就像一个魅力。

Have you seen a ymin parameter set to 0? That is the caveat! The y-axis will work with only integers if and only if you set your custom y-min and/or y-max boundaries. In my case it is doable as I know my data will present no values inferior to 0. Therefore, it works like a charm.

使用和使用补丁时:


这篇关于在morris.js折线图中将整数看作y轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 04:42