Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何自定义莫里斯曲线图的图例?_Java_Javascript_Date_Graph_Morris.js - Fatal编程技术网

Java 如何自定义莫里斯曲线图的图例?

Java 如何自定义莫里斯曲线图的图例?,java,javascript,date,graph,morris.js,Java,Javascript,Date,Graph,Morris.js,我正在使用库,我想自定义我的图表,以便正确格式化图例中的日期时间。此时,当我将类似于2013-07-26T03:34:41+02:00(ISO8601)的值传递给ykey时,生成的图例内容如下: 我想生成图例的内容,以便以用户友好的方式显示2013-07-26T03:34:41+02:00,可能类似于03:34:41(2013-07-26)或刚才的/19秒前的 可能吗?如果是这样,我该怎么做呢?使用下面的功能,并根据您的需要更换车身 hoverCallback: function (in

我正在使用库,我想自定义我的图表,以便正确格式化图例中的日期时间。此时,当我将类似于
2013-07-26T03:34:41+02:00
(ISO8601)的值传递给
ykey
时,生成的图例内容如下:

我想生成图例的内容,以便以用户友好的方式显示
2013-07-26T03:34:41+02:00
,可能类似于
03:34:41(2013-07-26)
刚才的
/
19秒前的


可能吗?如果是这样,我该怎么做呢?

使用下面的功能,并根据您的需要更换车身

   hoverCallback: function (index, options, content) {
   var row = options.data[index];
   //here row has x and y values
   }

使用以下功能,并根据需要更换车身

   hoverCallback: function (index, options, content) {
   var row = options.data[index];
   //here row has x and y values
   }

如果仅针对您瞄准的x标签的日期格式,则应使用dateFormat选项:

dateFormat: function (x) {
   return moment(x).calendar();
}
它不会更改默认的hoverCallback,只会影响x标签在悬停气泡中的显示方式


在我的示例中,我使用了moment.js lib使日期看起来更好。

如果只是针对您要瞄准的x标签的日期格式,那么您应该使用dateFormat选项:

dateFormat: function (x) {
   return moment(x).calendar();
}
它不会更改默认的hoverCallback,只会影响x标签在悬停气泡中的显示方式


在我的示例中,我使用了moment.js lib使日期看起来更好。

如果有人来这里寻找实际的图例,而不是在数据点上格式化悬停细节,Morris团队中的一个人会制作一把小提琴,展示如何使用一些js和CSS


#传奇{
高度:50px;
背景:rgba(1271271270.5)
}
#图例跨度{
显示:内联块;
填充:15px 30px;
位置:相对位置;
}
#图例跨度:之后{
左侧填充:4px;
内容:'\00a0\00a0\00a0\00a0\00a0\00a0\00a0';
文字装饰:线条贯通;
}
然后在JS下面添加以下内容:

chart.options.labels.forEach(function(label, i){
    var legendItem = $('<span></span>').text(label).css('color', chart.options.lineColors[i])
    $('#legend').append(legendItem)
})
chart.options.labels.forEach(函数(label,i){
var legendItem=$('').text(label.css('color',chart.options.lineColors[i])
$(“#图例”)。追加(legendItem)
})

如果有人来这里寻找一个真实的传说,而不是在数据点上格式化悬停细节,莫里斯团队的一名成员会做一个小提琴,展示如何使用一些JS和CSS


#传奇{
高度:50px;
背景:rgba(1271271270.5)
}
#图例跨度{
显示:内联块;
填充:15px 30px;
位置:相对位置;
}
#图例跨度:之后{
左侧填充:4px;
内容:'\00a0\00a0\00a0\00a0\00a0\00a0\00a0';
文字装饰:线条贯通;
}
然后在JS下面添加以下内容:

chart.options.labels.forEach(function(label, i){
    var legendItem = $('<span></span>').text(label).css('color', chart.options.lineColors[i])
    $('#legend').append(legendItem)
})
chart.options.labels.forEach(函数(label,i){
var legendItem=$('').text(label.css('color',chart.options.lineColors[i])
$(“#图例”)。追加(legendItem)
})