Andre Steenveld Report post Posted May 4, 2012 Hello all, I have been working with FusionCharts for a while now and I noticed some rather strange behaviour when setting JSON data on a chart to be rendered. Take this code for example: var data = { /* ... snip ... */ chart: { /* ... snip ... */ showlegend: true } }; chart.setJSONData( data ); chart.render( domNode ); If chart is a pie chart I would expect it to have a legend but the chart renders and there is no legend. According to the documentation we will have to use 1 or 0 to indicate so I tried this: var data = { /* ... snip ... */ chart: { /* ... snip ... */ showlegend: new Number( true ) // new Number( true ) == 1 but new Number( true ) !== 1 } }; chart.setJSONData( data ); chart.render( domNode ); Even though we have a Number now rendering the chart will throw a TypeError saying "Cannot read property 'pieYScale' of undefined". The work around is pretty obvious though: var data = { /* ... snip ... */ chart: { /* ... snip ... */ showlegend: legend ? 1 : 0, /* or you could automagically cast it to a number, this could cause some unexpected results though, some examples */ showlegend: new Number( legend ) + 0, showlegend: ~~ new Number( legend ) } }; chart.setJSONData( data ); chart.render( domNode ); legend being something that is truthy or falsy and sticking it in with the ?:-operator will make sure a literal is placed when you actually just need a boolean there. My questions: If any other value then 1 is supplied the legend will not render, but as long as it is a number literal nothing happens. Why is this, why not just use a boolean or the javascript type unsafe compare operator (==)? Also adding the showlegend property to the configuration of anything else then a Pie or Pie3d will cause it to show the message "Invalid data", is there a reason why its not just silently ignored? Best regards, André Share this post Link to post Share on other sites
Guest Sumedh Report post Posted June 15, 2012 Hello all, I have been working with FusionCharts for a while now and I noticed some rather strange behaviour when setting JSON data on a chart to be rendered. Take this code for example: var data = { /* ... snip ... */ chart: { /* ... snip ... */ showlegend: true } }; chart.setJSONData( data ); chart.render( domNode ); If chart is a pie chart I would expect it to have a legend but the chart renders and there is no legend. According to the documentation we will have to use 1 or 0 to indicate so I tried this: var data = { /* ... snip ... */ chart: { /* ... snip ... */ showlegend: new Number( true ) // new Number( true ) == 1 but new Number( true ) !== 1 } }; chart.setJSONData( data ); chart.render( domNode ); Even though we have a Number now rendering the chart will throw a TypeError saying "Cannot read property 'pieYScale' of undefined". The work around is pretty obvious though: var data = { /* ... snip ... */ chart: { /* ... snip ... */ showlegend: legend ? 1 : 0, /* or you could automagically cast it to a number, this could cause some unexpected results though, some examples */ showlegend: new Number( legend ) + 0, showlegend: ~~ new Number( legend ) } }; chart.setJSONData( data ); chart.render( domNode ); legend being something that is truthy or falsy and sticking it in with the ?:-operator will make sure a literal is placed when you actually just need a boolean there. My questions: If any other value then 1 is supplied the legend will not render, but as long as it is a number literal nothing happens. Why is this, why not just use a boolean or the javascript type unsafe compare operator (==)? Also adding the showlegend property to the configuration of anything else then a Pie or Pie3d will cause it to show the message "Invalid data", is there a reason why its not just silently ignored? Best regards, André Hi, Apologies for delaying. Could you please some provide information on following points? > What FusionCharts version used at your end? > Can you paste your sample code and XML here? So that we can test. Share this post Link to post Share on other sites