hiding year on date format

TeeChart for JavaScript for the HTML5 Canvas
Post Reply
goodsj
Newbie
Newbie
Posts: 18
Joined: Thu Jan 25, 2018 12:00 am

hiding year on date format

Post by goodsj » Fri Nov 23, 2018 2:24 am

before.jpg
before.jpg (12.62 KiB) Viewed 35385 times
current date format is show years (yyyy - mm - dd hh:ii:ss)


I wish to fix it like following pictures.

1 . Year format is displayed only first time or when next year
after.jpg
after.jpg (11.2 KiB) Viewed 35385 times

How to fix it like this picture?

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

Re: hiding year on date format

Post by Yeray » Fri Nov 23, 2018 3:02 pm

Hello,

Find below a simple example:
chrome_2018-11-23_16-03-22.png
chrome_2018-11-23_16-03-22.png (84.02 KiB) Viewed 35380 times

Code: Select all

      var Chart1;

      function draw() {
        Chart1 = new Tee.Chart("canvas1");

        Chart1.legend.visible = false;
        Chart1.axes.bottom.labels.dateFormat = "yyyy-mm-dd hh:MM:ss";

        var drawingLabels = false;
        var yearsDrawn;
        Chart1.axes.bottom.oldDrawLabels = Chart1.axes.bottom.drawLabels;
        Chart1.axes.bottom.drawLabels = function(){
          drawingLabels = true;
          yearsDrawn = [];
          this.oldDrawLabels();
          drawingLabels = false;
          console.log(yearsDrawn);
        }

        Chart1.axes.bottom.labels.ongetlabel = function(value, text) {
          if (drawingLabels) {
            console.log(text);
            var year = text.substr(0, 4);
            if (yearsDrawn.indexOf(year) === -1) {
              yearsDrawn.push(year);
            }
            else {
              text = text.substr(5);
            }
          }

          return text;
        }

        var series1 = Chart1.addSeries(new Tee.Line()).addRandom(500);

        var msecsInADay=86400000; //24*60*60*1000
        series1.data.x=new Array(series1.count());
        var now=new Date();
        for (var t=0; t<series1.count(); t++) {
          series1.data.x[t] = new Date(now.getTime() + t * msecsInADay);
        }

        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