javascript 图表4.1.1 Y轴刻度

ruarlubt  于 2022-12-21  发布在  Java
关注(0)|答案(1)|浏览(120)

我想在Y轴上设置最小和最大刻度,我已经尝试了suggestedMinminmax,但不起作用。
此消息显示在控制台Uncaught SyntaxError: Cannot use import statement outside a module

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.1.1/chart.min.js?ver=1"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.1.1/chart.umd.js"></script>

<canvas class="" id="myChart" height="280px"></canvas>
<script type="module">
        $(window).on("load",function() {
            // page is fully loaded, including all frames, objects and images
            
            var ctxChart = document.getElementById("myChart");
            ctxChart.height = 120;
            var myChart = new Chart(ctxChart, {

                type: "bar",
                data: {
                    labels: ["09/Aug/2021", "16/Aug/2021", "06/Sep/2021", "14/Oct/2021", "19/Oct/2021"],
                    datasets: [
                        {
                          label: "Max and Min - Day",
                          data: [["10000000", "10000000"], ["10000000", "10000000"], ["15000000", "10000000"], ["10000000", "10000000"], ["22000000", "22000000"]],
                          backgroundColor: "rgb(74,152,176, 0.5)",
                          order: 1
                        },
                        {
                          label: "Day Avg",
                          data: ["10000000", "10000000", "12500000", "10000000", "22000000"],
                          borderColor: "rgb(191,110,131)",
                          backgroundColor: "rgb(191,110,131)",
                          type: "line",
                          order: 0,
                          pointRadius: 5,
                          pointHoverRadius: 5
                        },
                        {
                          label: "Global Avg",
                          data: ["16000000", "16000000", "16000000", "16000000", "16000000"],
                          borderColor: "rgb(244,209,76)",
                          backgroundColor: "rgb(244,209,76)",
                          type: "line",
                          order: 0,
                          pointRadius: 3,
                          pointHoverRadius: 3
                        }
                    ]
                },
                options: {
                    responsive: true,
                    plugins: {
                        legend: {
                            position: "top",
                        },
                        title: {
                            display: true,
                            text: "Price"
                        },
                        subtitle: {
                            display: true,
                            text: "example.com"
                        }
                    },
                    scales: {
                        y: {
                            title: {
                                display: true,
                                text: "$"
                            }
                        }
                    }
                }
                
                
            });
        });
</script>
zphenhs4

zphenhs41#

您需要删除顶部的script标记,然后它才能正常工作。
所以你需要删除这一行:

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.1.1/chart.min.js?ver=1"></script>

相关问题