Chart.js折线图的0线样式

时间:2015-04-02 05:06:34

标签: javascript charts chart.js

我有一个折线图,其中包含用Chart.js写的正值和负值。 我试图让0线平行于X轴,而不影响其他图表元素。

我的代码:

line_chart_options: {
    responsive: false,
    maintainAspectRatio: true,
    multiTooltipTemplate: "<%= datasetLabel %>: $<%= addThousandCommas(value) %>",
    legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\">&nbsp;</span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
},

我试过了:

    scaleLineColor: "rgba(0,0,0,1)",

但这只是对轴进行着色,而不是0线。

我如何着色0线?

1 个答案:

答案 0 :(得分:0)

通过设置您输入图表的数据集中的填充颜色来处理线条颜色。最值得注意的是fillColor,strokeColor和pointColor。

以下是一个示例折线图对象,用于为图表中的2行/系列着色:

var obj=    {
                labels : ["January","February","March","April","May","June","July"],
                datasets : [
                    {
                        label: "My First dataset",
                        fillColor : "rgba(220,220,220,0.2)",
                        strokeColor : "rgba(220,220,220,1)",
                        pointColor : "rgba(220,220,220,1)",
                        pointStrokeColor : "#fff",
                        pointHighlightFill : "#fff",
                        pointHighlightStroke : "rgba(220,220,220,1)",
                        data : 1,2,3,4,5,6,7]
                    },
                    {
                        label: "My Second dataset",
                        fillColor : "rgba(151,187,205,0.2)",
                        strokeColor : "rgba(151,187,205,1)",
                        pointColor : "rgba(151,187,205,1)",
                        pointStrokeColor : "#fff",
                        pointHighlightFill : "#fff",
                        pointHighlightStroke : "rgba(151,187,205,1)",
                        data : [1,2,3,4,5,6,7]
                    }
                ]

            };