简体   繁体   English

如何使用Morris.js在单线图下添加颜色

[英]How to add color under a single line graph with Morris.js

I am currently using Morris.js to draw graphs for an Android application. 我目前正在使用Morris.js为Android应用程序绘制图形。 I pass in data that contains points for 1 single line. 我传入的数据包含1条单线的点。 Donations and Dates. 捐赠和日期。 I am trying to add color to the bottom side of the line graph but cannot figure out how to do it. 我正在尝试将颜色添加到折线图的底部,但无法弄清楚该怎么做。

这是我要复制的样式

This is the style I am trying to replicate. 这是我要复制的样式。

在此处输入图片说明

But under a single line. 但是下一行。

I have edited the Morris.js code and also passed in as many different options to Morris.Line but to no avail. 我已经编辑了Morris.js代码,还向Morris.Line传递了许多不同的选项,但无济于事。 This is currently the code I am using to setup the graph. 目前这是我用来设置图形的代码。 I thought the 'fillOpacity' option would work but it hasn't. 我以为'fillOpacity'选项可以工作,但没有。 Is there an option that I am missing? 我有没有一个选择? Or is there a duplicate answer to this I have passed over? 还是对此我有一个重复的答案?

    var xKey = "day"
    var yKey = 'funds'
    var jsonData

    var graph = Morris.Line({
            element: 'graph',
            data: jsonData,
            xkey: xKey,
            ykeys: [yKey],
            labels: ['funds gathered'],
            smooth: true,
            resize: true,
            parseTime: true,
            grid: false,
            fillOpacity: true
        });

    function setGraph(data) {
        graph.setData(data);
    }

Ok so the issue was that in the above example I am trying to instantiate a Morris.Line where actually what I want is a Morris.Area. 好的,问题是在上面的示例中,我试图实例化Morris.Line,而实际上我想要的是Morris.Area。

<script>
    var xKey = "day"
    var yKey = 'funds'
    var jsonData

    var graph = Morris.Area({
            element: 'graph',
            data: jsonData,
            xkey: xKey,
            ykeys: [yKey],
            labels: ['funds gathered'],
            smooth: true,
            resize: true,
            parseTime: true,
            grid: false
        });

    function setGraph(data) {
        graph.setData(data);
    }
</script>

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

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