Sign in to follow this  
Andre Steenveld

Unexpected Values When Setting Json Data

Recommended Posts

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this