chartjs/Chart.js

[Feature Request] Floating Legend In Chart Area

Open

#3,787 opened on 2017年1月12日

GitHub で見る
 (5 comments) (4 reactions) (0 assignees)JavaScript (67,416 stars) (11,951 forks)batch import
help wantedtype: enhancement

説明

I am considering using Chart.js because I have found it very simple to use and the ease of integrating live customization with events and the '.update()' function. The one exception is the legend seems like it only can form itself on the borders of the chart area. You can't really specify a position and have it form inside the chart area like most other graphing utilities.

I understand there could be some overlap and z-order issues with onHover/onClick events that could probably be the reason it hasn't been tackled yet. I think i'm going to try tackling this a bit this weekend, but curious if there is a real reason it hasn't been implemented yet.

Also: Here is a really basic plugin i wrote to give background color customization (background and chart area). Is there really no innate ability to do this? I'd strongly consider adding something similar also since this is clearly needed core functionality if the chart is converted to PNG or copy & pasted where it could be converted to 'rgb' from rgba. Plus a '0,0,0,0.0' default just seems bad when most charts have white backgrounds so would expect a default of '255,255,255,0.0'.

    //Background color plugin
    Chart.pluginService.register({
        beforeDraw: function (chart, easing) {
            var ctx = chart.chart.ctx;
            var chartArea = chart.chartArea;

            ctx.save();

            //Fill entire canvas
            ctx.fillStyle = chart.config.backgroundColor || 'rgba(255,255,255,0.0)';
            ctx.fillRect(0, 0, chart.chart.width, chart.chart.height);

            //Fill chart area
            ctx.fillStyle = chart.config.options.chartArea.backgroundColor || 'rgba(255,255,255,0.0)'
            ctx.fillRect(chartArea.left, chartArea.top, chartArea.right - chartArea.left, chartArea.bottom - chartArea.top);

            ctx.restore();
        }
    });

コントリビューターガイド

[Feature Request] Floating Legend In Chart Area · chartjs/Chart.js#3787 | Good First Issue