Skip to content

标记线 Markers

库提供标记扩展,允许您标记(突出显示)某些日期或日期范围。

js
const netGraph = new NetPlanGraph({
  keyboard: true,
})

// 等同于
const netGraph = new NetPlanGraph({
  keyboard: {
    enabled: true,
  },
})

添加标记

要向时间轴区域添加标记(例如今天的标记),请调用 addMarker 方法:

js
const markerId = netGraph.addMarker({
    start_date: new Date(), //a Date object that sets the marker's date
    css: "today", //a CSS class applied to the marker
    text: "Now", //the marker title
    title: 'Today' // the marker's tooltip
});

获取标记

若要获取添加标记的对象,请使用 getMarker 方法:

js
const markerId = netGraph.addMarker({
    start_date: new Date(), //a Date object that sets the marker's date
    css: "today", //a CSS class applied to the marker
    text: "Now", //the marker title
    title: 'Today' // the marker's tooltip
});

netGraph.getMarker(markerId); //->{css:"today", text:"Now", id:...}

更新标记

若要更新标记,请使用 updateMarker 方法:

js
const markerId = netGraph.addMarker({  
    start_date: new Date(), 
    css: "today", 
    text: "Now", 
    title: "today"
});

netGraph.updateMarker(markerId, {css: "today_new"});

删除标记

若要删除添加后的标记,请使用 deleteMarker 方法:

js
const markerId = netGraph.addMarker({
    start_date: new Date(), //a Date object that sets the marker's date
    css: "today", //a CSS class applied to the marker
    text: "Now", //the marker title
    title: 'Today' // the marker's tooltip
});

netGraph.deleteMarker(markerId); //->{css:"today", text:"Now", id:...}

隐藏标记

要隐藏所有添加的标记,请使用hideMarkers 方法:

js
const markerId1 = netGraph.addMarker({...})
const markerId2 = netGraph.addMarker({...})

netGraph.hideMarkers([markerId1, markerId2]);

Released under the MIT License.