Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display Error when using data labels and min and/or max values for the x-axis #414

Open
team-moeller opened this issue Mar 10, 2024 · 4 comments

Comments

@team-moeller
Copy link

When you decide to show data labels and also decide to use min and/or max values for the x-axis there is an error in the display.

@team-moeller
Copy link
Author

This is the original chart without min and max values for the x-axis:
image
The datalables are shown at the beginning and the color is red.

@team-moeller
Copy link
Author

This is the chart with values for min and max for the x-axis:
image
One can see the number "3" at the left side and the numbers 6, 9 and 4 on the right side.

@team-moeller
Copy link
Author

This is the underlying html code:

<!DOCTYPE html>
<html>
<head>
    <title>Chart</title>
    <meta charset='utf-8'>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.min.js'></script>
    <script src='https://cdn.jsdelivr.net/npm/chartjs-plugin-autocolors'></script>
    <script src='https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2.0.0'></script>
    <style>
        body { margin: 0; padding: 0; }
        #container { width: 100%; }
    </style>
</head>
<body>
<div id='container'>
    <canvas id='myChart'></canvas>
</div>
<script>
    Chart.register(window['chartjs-plugin-autocolors']);
    Chart.register(ChartDataLabels);
    Chart.defaults.animation.duration = 1000;
    Chart.defaults.animation.easing = 'linear';
    var ctx = document.getElementById('myChart').getContext('2d');
    var myChart = new Chart(ctx, {
        type: 'bar',
        data: {
            labels: ['Jan','Feb','Mar','Apr','May','Jun',],
            datasets: [
               {label: 'Dataset1' ,
                data: [ 5.5, 4, 7, 2, 5, 6],
                borderWidth: 1},
               {label: 'Dataset2' ,
                data: [ 4, 8, 3, 5, 1, 9],
                borderWidth: 1},
               {label: 'Dataset3' ,
                data: [ 3, 5, 7, 6, 2, 4],
                borderWidth: 1}
             ]
        },
        options: {
            aspectRatio:  1.6,
            scales: {
                y: {
                    id: 'first-y-Axis',
                    display: true,
                    title: {
                       display: true,
                       text: 'Demo y-axis'
                    }
                },
                x: {
                    id: 'first-x-Axis',
                    display: true,
                    title: {
                       display: true,
                       text: 'Demo x-axis'
                    },
                    min: 'Feb' ,
                    max: 'May' 
                }
            },
            plugins: {
                title: {
                    display: true,
                    position: 'top',
                    text: 'I love Better Access Charts'
                },
                subtitle: {
                    display: false,
                },
                legend: {
                    display: true,
                    position: 'right'
                },
                datalabels: {
                    anchor: 'start',
                    color: 'red',
                    font: {
                        size: 16
                        }
                    }
                }
        }
    });
</script>
</body>
</html>

@team-moeller
Copy link
Author

This issue is related to this one:
team-moeller/better-access-charts#170

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant