TeeChart for JavaScript for the HTML5 Canvas
-
sct
- Newbie
- Posts: 31
- Joined: Tue Aug 06, 2013 12:00 am
Post
by sct » Wed Aug 14, 2013 12:32 pm
The example show smoothing works but the way I use the 2d charts it does not.
here is my draw 2d function. Did I do anything wrong?
Code: Select all
chart.prototype.draw = function ()
{//makes a 2d chart
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, .05, "ellipse" );
else if ( this.type == "Table" )
{
for ( z = 0; z < this.Zdata.length;z++ )
{
this.addData( this.Ydata, this.Zdata[z], .05, "ellipse" );
}
}
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 ) );
this.Chart1.draw();
};
-
sct
- Newbie
- Posts: 31
- Joined: Tue Aug 06, 2013 12:00 am
Post
by sct » Wed Aug 14, 2013 12:34 pm
this is my addData where I try and add something.
Code: Select all
chart.prototype.addData = function ( xdata,ydata,smooth,style )
{
var dat = this.Chart1.addSeries( new Tee.Line() )
dat.smooth = smooth;
dat.data.values = eval( "[" + ydata.toString() + "]" );//will not take an array dirrectly, must eval its string.
dat.data.x = eval( "[" + xdata.toString() + "]" );
dat.data.labels = xdata
dat.cursor = "pointer";
dat.colorEach = "yes";
dat.pointer.style = style;
dat.pointer.visible = true;
dat.format.stroke.fill = "red"
var anno = this.annot;
dat.onclick = function ( series, index, x, y )
{
var xValue = series.data.x ? series.data.x[index].toFixed( 0 ) : index.toFixed( 0 );
anno.text = "X: " + xValue + "\nY: " + series.data.values[index].toFixed( series.decimals );
series.chart.draw();
}
this.datas.push( dat );
}
-
Yeray
- Site Admin
- Posts: 9613
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Mon Aug 26, 2013 10:21 am
Hi,
Note you have to include the teechart-extras.js.
-
sct
- Newbie
- Posts: 31
- Joined: Tue Aug 06, 2013 12:00 am
Post
by sct » Mon Aug 26, 2013 12:06 pm
steema/source/teechart-extras.js is included. Is it the ordering?
-
Yeray
- Site Admin
- Posts: 9613
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Tue Aug 27, 2013 3:51 pm
Hi,
Please, try it as in the demos.
I had to modify your code to make it work for me here, but it seems to work fine.
I had to define:
Code: Select all
this.Xdata = ["0", "1", "2", "3", "4"];
this.Ydata = ["0", "30", "40", "45", "50"];
this.type = "Function";
And to comment out removeChild, appendChild and datas.push.
- test.zip
- (1.19 KiB) Downloaded 1164 times
-
sct
- Newbie
- Posts: 31
- Joined: Tue Aug 06, 2013 12:00 am
Post
by sct » Wed Aug 28, 2013 12:22 pm
well it took me a long while to figure it out but i found it. You changed the 3rd parameter in addData to a .5 instead of my .05. This is the smoothing setting I guess .05 was not enough. Had to use a compare plugin to figure it out.
-
Yeray
- Site Admin
- Posts: 9613
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Thu Aug 29, 2013 10:47 am
Hi,
I'm glad to see you found it.