sgratzl / chartjs-chart-boxplot

Chart.js Box Plots and Violin Plot Charts
https://www.sgratzl.com/chartjs-chart-boxplot/
MIT License
101 stars 23 forks source link

Option usage #87

Closed T3chTobi closed 8 months ago

T3chTobi commented 8 months ago

Hello, I'm using the boxplot in Vanilla JS with the following code:

<script src="https://unpkg.com/chart.js@4"></script>
<script src="https://unpkg.com/@sgratzl/chartjs-chart-boxplot@4"></script>
<script>

    const boxplotData = {
        // define label tree
        labels: ['January'],
        datasets: [{
            label: 'Dataset 1',
            backgroundColor: 'rgba(255,0,0,0.5)',
            borderColor: 'red',
            borderWidth: 1,
            outlierColor: '#999999',
            padding: 10,
            itemRadius: 0,
            data: [
                [...]
            ],
            legend: {
                position: 'bottom',
            },
        }]
    };
    window.onload = () => {
        const ctx = document.getElementById("canvas").getContext("2d");
        window.myBar = new Chart(ctx, {
            type: 'boxplot',
            data: boxplotData,
            options: {
                indexAxis: 'y',
                responsive: true,
                legend: {
                    display: false,
                    position: 'top',
                },
                title: {
                    display: false,
                    text: 'Chart.js Box Plot Chart'
                },
            }
        });

    };

</script>

This is how it looks on the website:

Screenshot 2023-10-10 at 03 38 28

I would like to do the following things and tried the options inside the documentation, but it did not work:

How can I do that? The only parameter from options that seems to work is the indexAxis which works as intended. The other parameters don't work. I did not find parameters to set a custom height and width of the canvas.

lukaszahorec commented 8 months ago

Same here, I am using violin and also box plot and options.legend.display: false seem not to work, legend is still showing.

*Edit: @T3chTobi

Found a solution what works for me, try this:

options: { plugins: { tooltip: { enabled: false, }, legend: { display: false, }, }, }

sgratzl commented 8 months ago

this seems overall a chart.js question than a this plugin specific question. This plugin doesn't render the legend or title