You have trouble getting Highchart

I am new to Javascript, Rails, and JQuery that work together.

I look at this tutorial (http://www.highcharts.com/documentation/how-to-use#installation) on Highcharts and just try to show a basic graph. This is not happening.

In my home.html.erb file, I have:

<div id="container" style="width: 100%; height: 400px"></div>

In app/views/layouts/application.html.erbI have this in the tag head:

  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
  <script src="/public/highcharts.js" type="text/javascript"></script>

And this is the code in /public/highcharts.js:

var chart1; // globally available
$(document).ready(function() {
      chart1 = new Highcharts.Chart({
         chart: {
            renderTo: 'container',
            type: 'bar'
         },
         title: {
            text: 'Fruit Consumption'
         },
         xAxis: {
            categories: ['Apples', 'Bananas', 'Oranges']
         },
         yAxis: {
            title: {
               text: 'Fruit eaten'
            }
         },
         series: [{
            name: 'Jane',
            data: [1, 0, 4]
         }, {
            name: 'John',
            data: [5, 7, 3]
         }]
      });
   });

When the page loads, nothing appears, and I have no idea why. I did the tutorial 3 or 4 times, and Googled to answer to no avail. Any help would be greatly appreciated.

Edit: I changed the path in the script tag from /public/highcharts.jsto /highcharts.js. This gave me the following errors in my console debugger:

Uncaught ReferenceError: Highcharts is not defined highcharts.js:3
(anonymous function) highcharts.js:3
f.Callbacks.n jquery.min.js:2
f.Callbacks.o.fireWith jquery.min.js:2
e.extend.ready jquery.min.js:2
c.addEventListener.B
+5
source share
3

, .

  • Highcharts
  • script, .

, , :

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> 
<script src="/javascripts/js/highcharts.js" type="text/javascript"></script> <!--where you put the high charts library -->
<script src="/highcharts.js" type="text/javascript"></script> <!-- your script -->

, ( , 3.1+), javascripts . 3.1 app/assets/javascripts, public/javascripts , .

, script Asset Pipeline.

!

+7

, var charts; , .

+1

There is a problem with the Chart keyword. Please change how

new Highcharts.Chart ({Chart with a little c

+1
source

All Articles