0

I am totally new to html. I was asked to display a simple chart in JS in a page.

This is my code, I am not getting anything displayed.

<html>
    <head>
        <title>JS Charts</title>
        <script type="text/javascript" src="scripts/jscharts.js"></script>
    </head>
    <body>
        <script type="text/javascript" >
        var myData = new Array(['2005', 2], ['2006', 1], ['2007', 3], ['2008', 6]);
        var myChart = new JSChart('chartid', 'bar');
        myChart.setDataArray(myData);
        myChart.setBarColor('#42aBdB');
        myChart.setBarOpacity(0.8);
        myChart.setBarBorderColor('#D9EDF7');
        myChart.setBarValues(false);
        myChart.setTitleColor('#8C8383');
        myChart.setAxisColor('#777E81');
        myChart.setAxisValuesColor('#777E81');
        myChart.draw();
        </script>
    </body>
</html>
TiraULTI
  • 199
  • 1
  • 2
  • 15
  • What errors do you get in the browser's console? – j08691 Nov 28 '16 at 15:06
  • on which dom element you are drawing this chart? You need a dom element like div or span with an id or class or any other identifier to draw this chart – brk Nov 28 '16 at 15:09
  • JSChart not found. Is it a library I need to import? Can I do it just with java script? I need to make a really simple graph/chart @j08691 – TiraULTI Nov 28 '16 at 15:09
  • Sounds like your `src="scripts/jscharts.js"` is incorrect – j08691 Nov 28 '16 at 15:10

2 Answers2

1

You have to add <div id="chartid"></div> into your html document and set correct path for jscharts.js if it's not correct!

Andrew
  • 479
  • 5
  • 15
  • Is it a library? Do i have to add some kind of .js file? – TiraULTI Nov 28 '16 at 15:13
  • I did not used that library for any kind of reason. I just was asked to make a simple graph in javascript and browsing I found that. Is there a more simple way? @Andrew – TiraULTI Nov 28 '16 at 15:15
1

You need to have a dom reference for your chart :

You have a reference here :

var myChart = new JSChart('chartid', 'bar');

So you need an html reference like :

<div id="chartid"></div>

If you want a very simple chart bar with full working exemple maybe you should use highcharts : http://www.highcharts.com/demo/column-basic

Mat
  • 435
  • 3
  • 12