Error rendering macro with javascript

I just created a user macro as listed below. It produces a rendering error but I cannot see what to do about it. Adding the code using the html-macro it works perfectly fine. Thanks for help, BKS

## Macro title: Google Graph
## Macro has a body: N
## Body processing: No macro body
## Output: Selected output option
##
## Developed by: Firstname Lastname
## Date created: 15/09/2015
## Installed by: Firstname Lastname
##
## @param SourceFile:title=Quelldatei|type=string|required=true|desc=Gib den Pfad zur Quelldatei an
## @param DataType:title=Datentyp|type=enum|enumValues=tav,role|default=tav|desc=Datentyp gibt an nach welcher Logik die Quelldatei geparst werden muss
## @param ChartID:title=Chart ID|type=string|required=true|desc=Vergebe jedem Chart eine eindeutige ID
## @param ChartTitle:title=Chart-Titel|type=string|required=true|desc=Der Titel des Charts
## @param ChartType:title=Chart-Typ|type=enum|enumValues=column,pie,line|default=column|desc=Waehle den Typen
## @param ChartWidth:title=Breite der Abbildung|type=string|required=true|desc=Angabe in Pixel - ohne px
## @param ChartHeight:title=Höhe der Abbildung|type=string|required=true|desc=Angabe in Pixel - ohne px
## @param AxisVertTitle:title=Titel der vertikalen Achse|type=string|required=true|desc=Setze die Beschriftung für die vertikale Achse
## @param AxisHorTitle:title=Titel der horizontalen Achse|type=string|required=true|desc=Setze die Beschriftung für die horizontale Achse
<div id="chart_$paramChartID">
</div>
<script type="text/javascript" src="https://www.google.com/jsapi">
</script>
<script type="text/javascript" src="http://192.168.56.202:8090/download/attachments/1081346/DrawChart.js">
</script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
</script>
<script type="text/javascript">
$.ajax({
    type: "GET",
    url: "$paramSourceFile",
    success: function(csvData)
    {
        switch ("$paramDataType")
        {
            case "tav":
                var data = ProcessTAVData(csvData);
                break;
            default:
                var data = ProcessTAVData(csvData);
        }
        // Set a callback to run when the Google Visualization API is loaded.
        google.setOnLoadCallback(DrawChart(
            data,
            "$paramChartID",
            "$paramChartTitle",
            "$paramChartType",
            "$paramChartWidth",
            "$paramChartHeight",
            "$paramAxisHorTitle",
            "$paramAxisVertTitle"
        ));
    }
});
</script>

2 answers

1 accepted

2 votes
Accepted answer
Davin Studer Community Champion Sep 15, 2015

It's probably the $.ajax({. I've had issues with the velocity engine mistaking the $ as a velocity variable. Try this instead.

## @param AxisHorTitle:title=Titel der horizontalen Achse|type=string|required=true|desc=Setze die Beschriftung für die horizontale Achse


#set( $d = '$' )
 
<div id="chart_@paramChartID">
</div>
....
....
${d}.ajax({...
Stephen Deutsch Community Champion Sep 16, 2015

or you can just use jQuery instead of $

Davin Studer Community Champion Sep 16, 2015

Yup. That'll work too.

Thx, that was pretty obvious. ;) I just replaced the $ with 'jQuery' and now everything works fine! :)

Do you get any errors in the console when it tries to run on a page? 

Also, have you tried just removing pieces of the code until it works to try and pin point where it is failing?

Here are some things that you may want to check also:

https://answers.atlassian.com/questions/21353

https://answers.atlassian.com/questions/201855

 

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in New to Confluence

How to use Confluence Cloud for stakeholder management

Most of us don’t need much convincing that stakeholder management is important. It just makes sense that keeping everyone in-the-know on projects and assigning clearly defined roles is key to having ...

1,187 views 4 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you