javascript - Why are the default Chart.js legend boxes transparent rectangles? -
why default chart.js legend boxes transparent rectangles these:
how make them solid squares these instead? i've looked through http://www.chartjs.org/docs/latest/configuration/legend.html can't find relevant.
https://jsfiddle.net/askhflajsf/7yped1d5/ (uses latest master branch build)
var barchartdata = { labels: ["2013-03-09", "2013-03-16", "2013-03-23", "2013-03-30", "2013-04-06"], datasets: [{ bordercolor: "#3e95cd", data: [10943, 29649, 6444, 2330, 36694], fill: false, borderwidth: 2 }, { bordercolor: "#ff3300", data: [9283, 1251, 6416, 2374, 9182], fill: false, borderwidth: 2 }] }; chart.defaults.global.defaultfontfamily = "'comic sans ms'"; // disable pointers chart.defaults.global.elements.point.radius = 0; chart.defaults.global.elements.point.hoverradius = 0; var ctx = document.getelementbyid("bar-chart").getcontext("2d"); new chart(ctx, { type: 'line', data: barchartdata, options: { responsive: true, legend: { display: true, position: "right" }, title: { display: false }, scales: { xaxes: [{ type: "time", ticks: { minrotation: 90 } }] } } }); <script src="http://www.chartjs.org/dist/master/chart.bundle.min.js"></script> <canvas id="bar-chart"></canvas>
this because haven't set backgroundcolor property datasets (which responsible legend's fill color).
datasets: [{ backgroundcolor: "#3e95cd", bordercolor: "#3e95cd", data: [10943, 29649, 6444, 2330, 36694], fill: false, borderwidth: 2 }, { backgroundcolor: "#ff3300", bordercolor: "#ff3300", data: [9283, 1251, 6416, 2374, 9182], fill: false, borderwidth: 2 }] ᴡᴏʀᴋɪɴɢ ᴇxᴀᴍᴘʟᴇ ⧩
var barchartdata = { labels: ["2013-03-09", "2013-03-16", "2013-03-23", "2013-03-30", "2013-04-06"], datasets: [{ backgroundcolor: "#3e95cd", bordercolor: "#3e95cd", data: [10943, 29649, 6444, 2330, 36694], fill: false, borderwidth: 2 }, { backgroundcolor: "#ff3300", bordercolor: "#ff3300", data: [9283, 1251, 6416, 2374, 9182], fill: false, borderwidth: 2 }] }; chart.defaults.global.defaultfontfamily = "'comic sans ms'"; // disable pointers chart.defaults.global.elements.point.radius = 0; chart.defaults.global.elements.point.hoverradius = 0; var ctx = document.getelementbyid("bar-chart").getcontext("2d"); new chart(ctx, { type: 'line', data: barchartdata, options: { responsive: true, legend: { display: true, position: "right" }, title: { display: false }, scales: { xaxes: [{ type: "time", ticks: { minrotation: 90 } }] } } }); <script src="http://www.chartjs.org/dist/master/chart.bundle.min.js"></script> <canvas id="bar-chart"></canvas> 

Comments
Post a Comment