简体   繁体   English

ChartJS图例未添加

[英]ChartJS Legend Not Lining Up

I am creating a legend for a line graph that was generated using ChartJS. 我正在为使用ChartJS生成的折线图创建图例。 The problem I am running into is the color boxes in the legend are not lining up correctly. 我遇到的问题是图例中的颜色框未正确排列。 Here is how I generate the legend: 这是生成图例的方式:

var chartLegend = "<ul style=\"list-style-type: none;\">";
for(var i = 0; i < chartDatas.datasets.length; i++)
{
    chartLegend += "<li><div style=\"background-color:" + chartDatas.datasets[i].pointColor + ";height:20px; width:20px; float:left; margin:5px;\"></div>" + chartDatas.datasets[i].label + "</li>"
}

chartLegend += "</ul>";

Here is the full code 这是完整的代码

Is it possible to line up the boxes? 可以把盒子排好吗?

var chartLegend = "<ul style=\"list-style-type: none; padding:    0\">";
for(var i = 0; i < chartDatas.datasets.length; i++)
{
        chartLegend += "<li><span style=\"background-color:" + chartDatas.datasets[i].pointColor + ";height:20px; width:20px; display:inline-table; margin:5px;\"></span>" + chartDatas.datasets[i].label + "</li>"
}

demo 演示

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

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