简体   繁体   English

多折线图数据显示不正确但显示正确的数字

[英]Multi line chart data displays incorrectly but shows correct number

First to start of, It's most likely a common question but I am way too sleep deprived right now to be able to figure it out (I did try though haha)首先开始,这很可能是一个常见问题,但我现在睡眠不足,无法弄清楚(我确实尝试过哈哈)

Anyways the issue I am having is with multi axis line chart无论如何,我遇到的问题是多轴线图

I have 7 different lines with data ranging anywhere from 1 digit number to 5 digits numbers (eg. line 1 ranges from 10000-30000 while line 2 ranges between 0 and 9)我有 7 条不同的行,数据范围从 1 位数到 5 位数不等(例如,第 1 行的范围为 10000-30000,而第 2 行的范围为 0 到 9)

Now my issue is that the lines scale incorrectly, line 2 appears larger than line 1 even though the difference is massive (check the image, green line is the one with 34 as value yet it appears larger than all other lines现在我的问题是线条缩放不正确,第 2 行看起来比第 1 行大,即使差异很大(检查图像,绿线是 34 作为值但它看起来比所有其他线条都大

what am I missing to fix this?我缺少什么来解决这个问题?

        const data = {
        labels: lbs,
        datasets: [
            {
                label: 'Regular',
                data: <?php echo $regularjs;?>,
                fill: true,
                backgroundColor: 'rgba(194, 143, 68, 0.1)',
                borderColor: 'rgb(194, 143, 68)',
                yAxisID: 'y',
                tension: 0.4,
            },
            {
                label: 'Feed',
                data: <?php echo $feedjs;?>,
                fill: true,
                backgroundColor: 'rgba(68, 194, 160, 0.1)',
                borderColor: 'rgb(68, 194, 160)',
                yAxisID: 'y1',
                tension: 0.4,
            },
            {
                label: 'Recents',
                data: <?php echo $recentsjs;?>,
                fill: true,
                backgroundColor: 'rgba(156, 68, 194, 0.1)',
                borderColor: 'rgb(156, 68, 194)',
                yAxisID: 'y2',
                tension: 0.4,
            },
            {
                label: 'Search',
                data: <?php echo $searchjs;?>,
                fill: true,
                backgroundColor: 'rgba(194, 68, 68, 0.1)',
                borderColor: 'rgb(194, 68, 68)',
                yAxisID: 'y3',
                tension: 0.4,
            },
            {
                label: 'Popular',
                data: <?php echo $popularjs;?>,
                fill: true,
                backgroundColor: 'rgba(179, 194, 68, 0.1)',
                borderColor: 'rgb(179, 194, 68)',
                yAxisID: 'y4',
                tension: 0.4,
            },
            {
                label: 'Profile',
                data: <?php echo $profilejs;?>,
                fill: true,
                backgroundColor: 'rgba(68, 81, 194, 0.1)',
                borderColor: 'rgb(68, 81, 194)',
                yAxisID: 'y5',
                tension: 0.4,
            },
            {
                label: 'Recommended',
                data: <?php echo $recommendedjs;?>,
                fill: true,
                backgroundColor: 'rgba(194, 68, 123, 0.1)',
                borderColor: 'rgb(194, 68, 123)',
                yAxisID: 'y6',
                tension: 0.4,
            }
        ]
    };
    const config = {
        type: 'line',
        data: data,
        options: {
            responsive: true,
            interaction: {
                mode: 'index',
                intersect: false,
            },
            stacked: false,
            plugins: {
                title: {
                    display: true,
                    text: 'Daily Pack Visits'
                },
                legend:{display: true}
            },
            scales: {
                y: {
                    type: 'linear',
                    display: true,
                    position: 'left',
                    beginAtZero: true,
                },
                y1: {
                    type: 'linear',
                    display: true,
                    position: 'right',
                    beginAtZero: true,
                    grid: {drawOnChartArea: false,},
                    ticks: {
                        display: false
                    }
                },
                y2: {
                    type: 'linear',
                    display: true,
                    position: 'right',
                    beginAtZero: true,
                    grid: {drawOnChartArea: false,},
                    ticks: {
                        display: false
                    }
                },
                y3: {
                    type: 'linear',
                    display: true,
                    position: 'right',
                    beginAtZero: true,
                    grid: {drawOnChartArea: false,},
                    ticks: {
                        display: false
                    }
                },
                y4: {
                    type: 'linear',
                    display: true,
                    position: 'right',
                    beginAtZero: true,
                    grid: {drawOnChartArea: false,},
                    ticks: {
                        display: false
                    }
                },
                y5: {
                    type: 'linear',
                    display: true,
                    position: 'right',
                    beginAtZero: true,
                    grid: {drawOnChartArea: false,},
                    ticks: {
                        display: false
                    }
                },
                y6: {
                    type: 'linear',
                    display: true,
                    position: 'right',
                    beginAtZero: true,
                    grid: {drawOnChartArea: false,},
                    ticks: {
                        display: false
                    }
                }
            }
        },
    };
    const dailypacks = new Chart(
        document.getElementById('daily-visits'),
        config
    );

graph图形

This is because you map each dataset to its own y axis.这是因为您将每个数据集映射到其自己的 y 轴。 This means the y axis will go from min to max for that dataset so it looks like its wrong.这意味着该数据集的 y 轴将从最小值变为最大值,因此看起来是错误的。

If you want your data represented so its scalled correctly you just need to remove the yAxisID option in each dataset.如果您希望您的数据表示以便正确调用,您只需删除每个数据集中的yAxisID选项。 With this removed they all fall back to the default which is y so you only have 1 scale.删除后,它们都将恢复为默认值y ,因此您只有 1 个比例。

This will show the data correctly scaled这将显示正确缩放的数据

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

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