onGetLabel with fractions

TeeChart for Javascript for the HTML5 Canvas
Post Reply
Igor
Newbie
Newbie
Posts: 5
Joined: Tue Mar 25, 2014 12:00 am

onGetLabel with fractions

Post by Igor » Mon May 26, 2014 2:39 pm

Hi,
I add 3 points to simple line serie with X coordinates: 1, 1.5 and 2. Then I try to use onGetLabel to edit labels, but it seems that it doesn't fire for 1.5. Is it normal? If it is, how can I add custom label for point 1.5?

Yeray
Site Admin
Site Admin
Posts: 8719
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: onGetLabel with fractions

Post by Yeray » Tue May 27, 2014 1:29 pm

Hello,

I've tried this and the axis label at 1.5 seems to be correctly caught:

Code: Select all

  Chart1=new Tee.Chart("canvas1");
  
  var s = Chart1.addSeries(new Tee.Line(Chart1));
  s.data.x=[1,1.5,2];
  s.data.values=[1,2,2.5];
  
  Chart1.axes.bottom.increment=0.5;
  Chart1.axes.bottom.setMinMax(0.95, 2.05);
  
  Chart1.axes.bottom.labels.ongetlabel=function(value,s) {
    if (value==1.5) {
       this.format.font.fill="red";
       this.format.font.style="14px Verdana";
       return "OneDotFive";
    }
    else {
       this.format.font.fill="black";
       this.format.font.style="11px Tahoma";
       return s;
    }
  }
  
  Chart1.draw();
2014-05-27_1528.png
2014-05-27_1528.png (27.63 KiB) Viewed 2160 times
Are you using the latest TeeChart for JavaScript version?
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Igor
Newbie
Newbie
Posts: 5
Joined: Tue Mar 25, 2014 12:00 am

Re: onGetLabel with fractions

Post by Igor » Tue May 27, 2014 2:19 pm

The magic line was:

Code: Select all

Chart1.axes.bottom.increment=0.5;
Now it works! Thank you for help!

Igor
Newbie
Newbie
Posts: 5
Joined: Tue Mar 25, 2014 12:00 am

Re: onGetLabel with fractions

Post by Igor » Thu May 29, 2014 12:57 pm

I still don't get it. If I add point 1.7 to the line, it doesn't work for it. Setting Chart1.axes.bottom.increment to 0.1 doesn't help. Could you explain how onGetLabel works?

Yeray
Site Admin
Site Admin
Posts: 8719
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: onGetLabel with fractions

Post by Yeray » Thu May 29, 2014 1:47 pm

Hi Igor,

Debugging, I've seen the ongetlabel event was being fired, but value was 1.7000000000000006, not 1.7.
Changing the condition for this, it works fine for me:

Code: Select all

  Chart1=new Tee.Chart("canvas1");
  
  var s = Chart1.addSeries(new Tee.Line(Chart1));
  s.data.x=[1,1.5,1.7,2];
  s.data.values=[1,2.5,2,2];
 
  Chart1.axes.bottom.increment=0.1;
  Chart1.axes.bottom.setMinMax(0.95, 2.05);
 
  Chart1.axes.bottom.labels.ongetlabel=function(value,s) {
    var v=value.toFixed(trunc(value)==value ? 0 : this.decimals);
    if ((v==1.5) || (v==1.7)) {
       this.format.font.fill="red";
       this.format.font.style="14px Verdana";
       return s;
    }
    else {
       this.format.font.fill="black";
       this.format.font.style="11px Tahoma";
       return s;
    }
  }
  
  Chart1.draw();
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply