Home forums Feature Requests & Feedback problem with code

This topic contains 1 reply, has 2 voices, and was last updated by  Anjali 1 year, 6 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #8736

    shvan
    Member

    I copy and paste this into my html file but its not working even with 3 browsers. any help??

    <!DOCTYPE HTML>
    <html>

    <head>
    <script type=”text/javascript”>
    window.onload = function () {
    // initial values of dataPoints
    var dps = [
    {label: “Management Wing”, y: 125} ,
    {label: “Production Lab”, y: 332},
    {label: “Cafeteria”, y: 55},
    {label: “Library”, y: 46},
    {label: “Recreation Centre”, y: 32}
    ];
    var totalEmployees = “total people on campus: 590”;

    var chart = new CanvasJS.Chart(“chartContainer”,{
    theme: “theme2”,
    title:{
    text: “People On Campus”
    },
    axisY: {
    title: “Number of People”
    },
    legend:{
    verticalAlign: “top”,
    horizontalAlign: “centre”,
    fontSize: 18

    },
    data : [{
    type: “column”,
    showInLegend: true,
    legendMarkerType: “none”,
    legendText: totalEmployees,
    indexLabel: “{y}”,
    dataPoints: dps
    }]
    });

    // renders initial chart
    chart.render();

    var sum = 590; //initial sum

    var updateInterval = 1000; // milliseconds

    var updateChart = function () {
    // Selecting a random dataPoint
    var dataPointIndex = Math.round(Math.random()*4);

    // generating random value
    var deltaY = Math.round(2 + Math.random() *(-2-2));

    // adding random value to random dataPoint
    dps[dataPointIndex].y = (dps[dataPointIndex].y + deltaY) > 0 ? dps[dataPointIndex].y + deltaY : 0 ;

    // updating legend text.
    sum = sum + deltaY;
    totalEmployees = “total people on campus: ” + sum;
    chart.options.data[0].legendText = totalEmployees;

    chart.render();

    };
    // update chart after specified interval
    setInterval(function(){updateChart()}, updateInterval);

    }
    </script>

    <script type=”text/javascript” src=”/assets/script/canvasjs.min.js”></script>
    </head>
    <body>
    <div id=”chartContainer” style=”height:300px; width:100%;”>
    </div>
    </body>

    </html>

    #8853

    Anjali
    Participant

    shvan,

    Code contains relative link to canvasjs.min.js on our server. Hence it won’t work unless you download the same and set proper path. Please download the latest version and try again.

    __
    Anjali

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

You must be logged in to reply to this topic.