如何从Label图表js获取行x值

问题描述 投票:1回答:1

我想用js创建一个图表。通过从sql和get条件中选择数据,我从Label获得标签行x的值,但是当我设置labels = Label时,图表没有显示。 请帮助我,我试着尝试每一个建议。

lbldate.Text = lbldate.Text + D1 +“,”+ D2 +“,”+ D3 +“,”+ D4 +“,”;

 <script type="text/javascript">

          var ldate = $('[id*=lbldate]').val();

          var config = {
              type: 'line',
              data: {
                  labels: ldate,
                  datasets: [{
                      label: "My First dataset",
                      data: [65, 40, 80, 81, 56, 85, 45],
                      backgroundColor: "rgba(255,99,132,0.2)",
                  }, {
                      label: "My Second dataset",
                      data: [40, 80, 21, 56, 85, 45, 65],
                      backgroundColor: "rgba(99,255,132,0.2)",
                  }]
              },
              scales: {
                  xAxes: [{
                      gridLines: {
                          display: false,
                          lineWidth: 1,
                          zeroLineWidth: 1,
                          zeroLineColor: '#666666',
                          drawTicks: false
                      },
                      ticks: {
                          display: true,
                          stepSize: 0,
                          min: 0,
                          autoSkip: false,
                          fontSize: 11,
                          padding: 12
                      }
                  }],
                  yAxes: [{
                      ticks: {
                          padding: 5
                      },
                      gridLines: {
                          display: true,
                          lineWidth: 1,
                          zeroLineWidth: 2,
                          zeroLineColor: '#666666'
                      }
                  }]
              },
              spanGaps: true,
              responsive: true,
              maintainAspectRatio: true
          };

          var ctx = document.getElementById("myChart").getContext("2d");
          new Chart(ctx, config);
  </script>
<asp:Label ID="lbldate" runat="server" Text=""></asp:Label>

<div class="myChart">
<canvas id="myChart"></canvas>
</div>
c# charts chart.js
1个回答
0
投票

检查创建新图表https://www.chartjs.org/docs/latest/developers/charts.html,您缺少选项,结构应如下所示:

    new Chart(ctx, {
        type: 'MyType',
        data: data,
        options: options
    });

接下来的事情是你发送到图表的标签应该是数组,你不能写像labels: something它应该是labels: [something],因为它试图用标签映射数组而你没有数组,然后它再现错误。

© www.soinside.com 2019 - 2024. All rights reserved.