1

I want to create a Chart in js. I get the value for labels line x from Label by selecting data from sql and get condition, but when I set labels = Label, the Chart does not show.
Please help me, I tried to try every suggestion.

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>
Aars93
  • 379
  • 4
  • 10
mam
  • 87
  • 1
  • 9

1 Answers1

0

Check creating new chart https://www.chartjs.org/docs/latest/developers/charts.html, you are missing options, structure should look like:

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

Next thing is that labels what you send to chart should be in array, you can't write like labels: something it should be labels: [something], because it's trying to map array with labels and you don't have array, then it reproduces error.

Alien
  • 258
  • 3
  • 10
  • Thanks for the advice now can do And from the advice from https://stackoverflow.com/questions/37090625/chartjs-new-lines-n-in-x-axis-labels-or-displaying-more-information-around-ch – mam Feb 27 '19 at 04:43