Page 1 of 1

Chart.draw(); gives error d.toFixed is not a function?

Posted: Fri Jul 11, 2014 1:35 pm
by 17766684
I have some code that worked with steema some time last year and I just updated to the saltest. Going through the code to make sure all is in order and ran in to this error. Here is my code leading up to the error. The very last line causes the error.

Code: Select all

         this.UIDiv.removeChild( this.canvas );
         this.canvas = document.createElement( 'canvas' );
         this.canvas.id = "canvas" + this.id;
         this.canvas.width = this.canvasData_width;
         this.canvas.height = this.canvasData_height;
         this.canvas.style.zIndex = this.canvasData_zIndex;
        // this.canvas.style.background = "#ffffff"
         this.UIDiv.appendChild( this.canvas );
         this.Chart1 = new Tee.Chart( "canvas" + this.id );

         this.annot = new Tee.Annotation( this.Chart1 );
         this.annot.position.x = 15;
         this.annot.position.y = 20;
         var anno = this.annot
         this.annot.mousemove = function () { this.text = ""; }

         if ( this.type == "Function" ) this.addData( this.Xdata, this.Ydata, .5, "ellipse" );
         else if ( this.type == "Table" )
         {
             for ( z = 0; z < this.Zdata.length;z++ )
             {
                 this.addData( this.Ydata, this.Zdata[z], .5, "ellipse" );
             }
         }
         //this.Chart1.legend.textStyle = "values"
         //this.Chart1.legend.legend_textstyle = "label"

         this.Chart1.tools.add( this.annot );
         this.Chart1.title.text = ""; 
         this.Chart1.axes.left.title.text = this.labelY; 
         this.Chart1.axes.bottom.title.text = this.labelX; 
         this.Chart1.tools.add( new Tee.DragTool( this.Chart1 ) ); alert( 5 )
         this.Chart1.draw();

Re: Chart.draw(); gives error d.toFixed is not a function?

Posted: Fri Jul 11, 2014 3:30 pm
by yeray
Hello,

Could you please arrange a simple example we can run as-is to reproduce the problem here?
To attach an htm file you may have to zip it before.

Thanks in advance.

Re: Chart.draw(); gives error d.toFixed is not a function?

Posted: Fri Jul 11, 2014 4:12 pm
by 17766684
this seems to do it.

Re: Chart.draw(); gives error d.toFixed is not a function?

Posted: Mon Jul 14, 2014 11:11 am
by yeray
Hello,

It seems to crash because it expects the data to be doubles, not strings, when executing this line with d being the first value in the series "0":

Code: Select all

return d.toFixed(0);
I'm trying to identify what change in the sources affected this. Can you tell us in what version did that example work fine?

Re: Chart.draw(); gives error d.toFixed is not a function?

Posted: Mon Jul 14, 2014 12:53 pm
by 17766684
could have something to do with this
(see number 2) "how to use an array without eval'ing it? "
http://www.teechart.net/support/viewtop ... 18&t=14255
I had issues with that before.

This is what I found in the read me
Release Notes 14th December 2012
TeeChart for JavaScript v1.4
Sourcecode version 2012.12.14.1.4

Re: Chart.draw(); gives error d.toFixed is not a function?

Posted: Mon Jul 14, 2014 1:01 pm
by 17766684
I made it work with
this.addData( eval( "["+Xdata +"]"), eval( "["+Ydata+"]" ), .5, "ellipse" );
but not I get this error.
TypeError: text.split is not a function

Re: Chart.draw(); gives error d.toFixed is not a function?

Posted: Tue Jul 15, 2014 11:13 am
by yeray
Hello,

If the input data is going to be in that format, what about calling addData without changing any type and doing the job inside it?
Ie:

Code: Select all

addData( Xdata, Ydata, .5, "ellipse" );

Code: Select all

         dat.data.values = eval("["+ydata+"]");
         dat.data.x = eval("["+xdata+"]");
         dat.data.labels = xdata;

Re: Chart.draw(); gives error d.toFixed is not a function?

Posted: Tue Jul 15, 2014 12:46 pm
by 17766684
This works, will this be the best practices or would the API accept text at some point?

Re: Chart.draw(); gives error d.toFixed is not a function?

Posted: Tue Jul 15, 2014 3:17 pm
by yeray
Hello,

I've added it to the wish list to be further investigated if we can implement some extra code to handle this situation:
http://bugs.teechart.net/show_bug.cgi?id=848

But in the meanwhile I'd consider the developer is the responsible to make sure data.x and data.values will receive arrays of numbers and data.labels will be an array of strings.

Re: Chart.draw(); gives error d.toFixed is not a function?

Posted: Tue Jul 15, 2014 4:48 pm
by 17766684
great thx.