My Rose chart isn't finding the canvas

« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by jose luis on 13th May 2014
I'm new to javascript and I am attempting to insert a Rose graph inside an info window. Everything works fine if I just create the canvas and paint a simple line, but when I replace the line by the rose graph the program stops.
I debugget the error and I found that the problem is when creating the rose graph with:

var windrose = new RGraph.Rose('cvs2', [4, 6, 3, 5, 2, 8, 9]);

This function calls

var tmp = RGraph.getCanvasTag(id); in RGraph.rose.js where tmp should be tmp[id, canvas].

In my case tmp is tmp[id, null]

Thanks a lot for the help!

Here is the code:

<!DOCTYPE html>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
     <!--The viewport meta tag is used to improve the presentation and behavior
     of the samples on iOS devices-->
     <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
     <title>Working on chart</title>
     <link rel="stylesheet" href="\">
     <link rel="stylesheet" href="\">
       html, body{
         height: 100%;
         width: 100%;
         margin: 0;
         padding: 0;
         margin: 0;
         padding: 0;
       .chart {
         padding:0px !important;

       <script src="../RGraph/libraries/RGraph.common.core.js" type="text/javascript"></script>
       <script src="../RGraph/libraries/RGraph.rose.js" type="text/javascript"></script>

     <script src="\"></script>
     <!--[if lt IE 9]><script src="../excanvas/excanvas.js"></script><![endif]-->

     <script src="\"></script>
         $(document).ready(function () {
             var rose = new RGraph.Rose('cvs', [4, 6, 3, 5, 2, 8, 9])
             .set('background.grid.spokes.overhang', 0) // 0 is the default

         var map;

         "esri/map", "esri/layers/FeatureLayer",
         "esri/dijit/InfoWindow", "esri/InfoTemplate",
         "esri/symbols/SimpleFillSymbol", "esri/renderers/SimpleRenderer",
         "dijit/layout/ContentPane", "dijit/layout/TabContainer",
         "dojo/dom-construct", "dojo/dom-class",
         "dojo/number", "dojo/domReady!"
       ], function (
         Map, FeatureLayer,
         InfoWindow, InfoTemplate,
         SimpleFillSymbol, SimpleRenderer,
         ContentPane, TabContainer,
         domConstruct, domClass,
         number, parser
       ) {

           // Use the info window instead of the popup.
           var infoWindow = new InfoWindow(null, domConstruct.create("div"));

           map = new Map("map", {
               basemap: "streets",
               center: [-113.405, 43.521],
               infoWindow: infoWindow,
               zoom: 6
           map.infoWindow.resize(300, 350);

           var template = new esri.InfoTemplate();
           // Flag icons are from, released under creative commons.
           template.setTitle("<b><img src='flags/${STATE_ABBR}.png'> ${STATE_NAME}</b>");

           var statesLayer = new FeatureLayer("\", {
               mode: FeatureLayer.MODE_ONDEMAND,
               infoTemplate: template,
               outFields: ["*"]
           var symbol = new SimpleFillSymbol();
           statesLayer.setRenderer(new SimpleRenderer(symbol));


           function getWindowContent(graphic) {
               // Make a tab container.
               var tc = new TabContainer({
                   style: "width:100%;height:100%;"
               }, domConstruct.create("div", { id: "parent1" }, tc));

               // Display attribute information.
               var cp1 = new ContentPane({
                   title: "Details",
                   content: "<a target='_blank' href='\" +
               graphic.attributes.STATE_NAME + "'>Wikipedia Entry</a><br><br>Median Age: " +
               graphic.attributes.MED_AGE + "<br>Median Age (Male): " +
               graphic.attributes.MED_AGE_M + "<br>Median Age (Female): " +
               // Display a dojo pie chart for the male/female percentage.
               var cp2 = new ContentPane({
                   title: "Pie Chart"

               //Create the chart that will display in the second tab.
               var c = domConstruct.create("div", {
                   id: "demoChart"
               }, domConstruct.create("div"));

               var c2 = domConstruct.create("canvas", {
                   id: "cvs2",
                   width: "300",
                   height: "300",
                   style: "border:1px solid #000000;"
               }, c);

     , c,"after")

// var ctx = c2.getContext("2d");
// ctx.moveTo(0, 0);
// ctx.lineTo(200, 100);
// ctx.stroke();

               var windrose = new RGraph.Rose('cvs2', [4, 6, 3, 5, 2, 8, 9]);
               //domClass.add(chart, "chart");

               cp2.set("content", c);

               return tc.domNode;
   <body class="claro">
       <div id="chartdiv">
       <canvas id="cvs" width="200" height="200">[No canvas support]</canvas>
     <div id="map"></div>

Posted by Richard on 14th May 2014

The canvas ID you're using in the constructor is cvs2 but your canvas tag ID is cvs - so when you create the object it won't be able to find the canvas.


Add a reply

« Back to message list