Home Forums Chart Support Can't create chart from external api link

Can't create chart from external api link

Viewing 4 posts - 1 through 4 (of 4 total)
  • #24030

    Hello everyone!
    This is my first time with CanvasJs.
    I’m trying to create a chart from my local api link.
    Here is my code:

    $.ajax({
      type: 'GET',
      url: 'http://localhost:8083/json',
      dataType: 'json',
      success(data) {
        new CanvasJS.Chart("chartContainer", {
          title: {
            text: "User Count"
          },
          data: [{
            type: "column",
            dataPoints: data.map(
              ({ userId, numberOfusers }) => ({ label: userId, y: numberOfusers })
            )
          }]
        }).render();
      }
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/canvasjs/1.7.0/canvasjs.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <br><br>
    <div id="chartContainer" style="height: 360px; width: 100%;"></div>

    But it return white page. Can someone help me? Thank you very much!

    #24034

    @murcie96,

    Can you kindly share a sample project with sample JSON data over google-drive or onedrive so that we can understand it better and help you out?

    ___________
    Indranil Deo,
    Team CanvasJS

    #24037

    Thanks for your reply! I fixed.
    I need to allow origin for my server side. Then I can use localhost api link to create chart.

    #24087

    @murcie96,

    Glad you figured out the issue.

    ___________
    Indranil Deo,
    Team CanvasJS

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.