0

I'm trying to render a partial in my app, but for some reason it will not render. I think it has to do with my asset pipeline and the fact that I am not correctly implementing the JavaScript I want to use in my partial. A test partial with a simple sentence works just fine. Can someone direct me in the proper use of JavaScript in my app?

Here is a jsFiddle of what I am trying to show: http://jsfiddle.net/yZQg4/

Problematic partial:

<%= javascript_include_tag "highcharts", "exporting", "jquery-1.4.2.min", "rails" %>

<script type="text/javascript" charset="utf-8">
  $(function() {
    var chart;
    $(document).ready(function() {
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'panel_contents',
                type: 'column'
            },

            xAxis: {
                categories: ['Automotive', 'Agency', 'Contractor', 'Country Club', 'Other']
            },
            yAxis: {
                min: 0,

                title: {
                    text: 'Business Summary'
                },
                stackLabels: {
                    enabled: true,
                    style: {
                        fontWeight: 'bold',
                        color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
                    }
                }
            },
            legend: {
                align: 'right',
                x: 100,
                verticalAlign: 'top',
                y: 0,
                floating: true,
                backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white',
                borderColor: '#CCC',
                borderWidth: 1,
                shadow: false
            },
            tooltip: {
                formatter: function() {
                    return '<b>' + this.x + '</b><br/>' + this.series.name + ': ' + this.y + '<br/>' + 'Total: ' + this.point.stackTotal;
                }
            },
            plotOptions: {
                column: {
                    stacking: 'normal',
                    dataLabels: {
                        enabled: true,
                        color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
                    }
                }
            },
            series: [{
                name: 'Mobile',
                data: [5, 3, 4, 27, 2]},
            {
                name: 'Foursquare',
                data: [2, 2, 3, 2, 1]},
            {
                name: 'Facebook',
                data: [3, 4, 4, 2, 5]},
            {
                name: 'Yelp',
                data: [3, 4, 4, 2, 5]},
            {
                name: 'Google',
                data: [3, 4, 4, 2, 5]}]
        });
    });

});​​
</script>

Working test partial:

<h1> hello world </h1>

Thanks!

Slicekick
  • 2,119
  • 5
  • 24
  • 35

2 Answers2

0

Add before the javascript code this:

<div id="panel_contents"></div>

P.S. Besides it's better move javascript inclusion out of partial or using a content_for

vlain
  • 712
  • 7
  • 13
  • I had that before, but for some reason I removed it. I just included it but the partial is still not appearing. – Slicekick Jun 27 '12 at 17:07
  • Move js include into your layout. Does Firebug (Firefox) or Chrome console give you any error? – vlain Jun 27 '12 at 17:11
  • I moved it, and inspected with Chrome console. This error shows up - `Uncaught SyntaxError: Unexpected token ILLEGAL` – Slicekick Jun 27 '12 at 17:24
  • Ok, I ran a full stack trace with Firebug. This is what it says `Illegal character` and it is pointing to the last line of my JavaScript. – Slicekick Jun 27 '12 at 17:41
0

I just recreated the file in TextEdit, and it worked. For some reason TextMate was secretly adding this to the file: &#8203;.

Slicekick
  • 2,119
  • 5
  • 24
  • 35