【问题标题】:JS Charts suggestedMin suggestedMax not workingJS 图表建议最小建议最大不工作
【发布时间】:2021-09-06 16:36:14
【问题描述】:

我是 JSCharts 的新手,我有两个图表,但它们的大小不同,我怎样才能使它们的大小相同?我已经在折线图中尝试了建议的最小值和建议的最大值,但它仍然从 0 开始 Y 刻度。另外,我想确保两个封闭的图表高度相同,线假设为气泡图。

<script>
  var areachart = document.getElementById("lineprices").getContext("2d");
  const historic_mean = JSON.parse("{{historic_mean|escapejs}}");
  const historic_max = JSON.parse("{{historic_max|escapejs}}");
  const historic_min = JSON.parse("{{historic_min|escapejs}}");
  const historic_dates = JSON.parse("{{historic_dates|escapejs}}");
  console.log("historic_mean", historic_mean);
  console.log("historic_max", historic_max);
  console.log("historic_min", historic_min);
  console.log("historic_dates", historic_dates);

  var configareachart = new Chart(areachart, {
    type: "line",
    data: {
      labels: historic_dates,
      datasets: [
        {
          label: "My First dataset",
          borderWidth: "2",
          borderColor: "#5B92FF",
          backgroundColor: "rgba(0, 0, 0, 0)",
          data: historic_max,
        },
        {
          label: "My Second dataset",
          borderWidth: "2",
          borderColor: "#F85778",
          backgroundColor: "rgba(0, 0, 0, 0)",
          data: historic_mean,
        },
        {
          label: "My Third dataset",
          borderWidth: "2",
          borderColor: "#1FC96E",
          backgroundColor: "rgba(0, 0, 0, 0)",
          data: historic_min,
        },
      ],
    },
    options: {
      responsive: true,
      maintainAspectRatio: false,
      elements: {
        point: {
          radius: 0,
        },
      },
      title: {
        display: false,
        text: "Chart.js Line Chart - Stacked Area",
      },
      tooltips: {
        mode: "index",
      },
      hover: {
        mode: "index",
      },
      legend: {
        display: false,
      },
      scales: {
        xAxes: [
          {
            ticks: {
              display: true,
              fontColor: "#90b5ff",
            },
            scaleLabel: {
              display: false,
              labelString: "Month",
            },
          },
        ],
        yAxes: [
          {
            ticks: {
              display: true,
              fontColor: "#90b5ff",
              suggestedMin: 10000,
              suggestedMax: 100000,
              stepValue: 5000,
            },
          },
        ],
      },
    },
  });
</script>

【问题讨论】:

    标签: javascript jscharts


    【解决方案1】:

    显然,不要使用

    responsive: true,
    maintainAspectRatio: false,
    

    【讨论】:

      猜你喜欢
      • 2020-02-26
      • 1970-01-01
      • 2014-05-17
      • 2018-02-04
      • 1970-01-01
      • 1970-01-01
      • 2015-12-15
      • 2012-04-23
      • 2013-10-22
      相关资源
      最近更新 更多