gpt4 book ai didi

javascript - 如何使用范围和导航器功能在 Highcharts 中创建列范围图表?

转载 作者:IT王子 更新时间:2023-10-29 02:44:21 24 4
gpt4 key购买 nike

我需要在 Highcharts 中绘制任务运行历史。它需要将任务的运行历史记录显示为水平条。我在下面添加了其他要求作为更新。最近我发现 StockChart 不支持 inverted 选项而且只有navigator & rangeSelector在 StockChart 中可用。因此我正在使用这些功能。

所以为了达到要求,我创建了类似于 this jsfiddle example 的东西(在浏览时在某处发现不记得来源)并以 this plunker link 结尾在我以前的帮助下question , 感谢 Pawel Fus

更新问题以避免混淆

附加要求:

显示仅那些在特定日期和时间范围运行的任务。如果运行次数太多,例如超过 10 次,则需要一种方法来仅显示 10 个任务,并使用可滚动的 y 轴显示其他任务。 plunker link to the problem

上述plunker的问题说明

如果你从上面的 plunker 查看下面的截图,时间范围是从 12/12/2014 09:32:2612/12/2014 10:32:26 并且只有 2 个任务运行了 m_ARRAYV_SALES_ZIG1_CALL2_VOD__C_OBm_ZIG2_HCP_MERGE_IB_CN。但是,我可以在 LILLY_C 之间看到另一个任务,它甚至没有在此日期时间范围内运行。 (在实际数据中有超过 10 个任务打乱了这个图表,甚至不在这个日期时间范围内)

此外,如果您注意到最右下角的时间从 09:38 变为 19:2019:20m_ZIG2_HCP_MERGE_IB_CN 任务的结束时间。 enter image description here下面是我的图表选项

    var chart_options = {
chart: {
renderTo: 'container',
height: 600
},
title: {
},
credits: {
enabled: false
},
xAxis: {
type: 'datetime',
gridLineWidth: 1,
tickInterval: 1 * 3600 * 1000,
dateTimeLabelFormats: {
month: '%b %e, %Y'
}
},
yAxis: {
tickInterval: 1,
gridLineWidth: 1,
labels: {
formatter: function() {
if (tasks[this.value]) {
return tasks[this.value].name;
}
}
},
startOnTick: false,
endOnTick: false,
title: {
text: 'Task'
}
},
rangeSelector: {
selected: 0,
buttons: [ {
type: "minute",
count: 60,
text: "1h"
}, {
type: "minute",
count: 180,
text: "3h"
}, {
type: "minute",
count: 300,
text: "5h"
}],
inputDateFormat: '%m/%d/%Y %H:%M:%S',
inputEditDateFormat: '%m/%d/%Y %H:%M:%S',
inputBoxWidth: 120
},
navigator: {
enabled: false
},
legend: {
enabled: false
},
tooltip: {
shared: false,
formatter: function() {
var str = '';
str += 'Task: ' + this.series.name + '<br>';
str += 'From: ' + Highcharts.dateFormat('%m/%d/%y %H:%M', this.point.from) + '<br>';
str += 'To: ' + Highcharts.dateFormat('%m/%d/%y %H:%M', this.point.to) + '<br>';
return str;
}
},
plotOptions: {
line: {
lineWidth: 10,
marker: {
enabled: true
},
dataLabels: {
enabled: true,
align: 'left',
formatter: function() {
return this.point.options && this.point.options.label;
}
},
states:{
hover:{
lineWidth:10
}
}
},
series: {
cursor: 'pointer',
point: {
events: {
click: function () {
var query = '{ "task_id": "'+this.task_id+'","start_time": '+this.from+',"exclude_interval": '+opExcludeMinutes+',"size": 10 }';
$scope.taskName = this.series.name;
$scope.isTaskSelected = false;
$scope.operationalReportAgentTaskHistoryServiceRequest(query);
}
}
}
}
},
series: seriesData
};

最佳答案

经过几个小时的挖掘,我刚刚找到了罪魁祸首(或者我真的希望如此)。问题是您对 yAxis 标签格式化程序的定义:

yAxis: {
tickInterval: 1,
gridLineWidth: 1,
labels: {
formatter: function() { // THIS IS THE PROBLEM
if (tasks[this.value]) {
return tasks[this.value].name;
}
}
},
startOnTick: false,
endOnTick: false,
title: {
text: 'Task'
}
},

您实际上并没有根据 task.intervals 检查是否应该显示标签(参见 json.js)。格式化程序的简单更新 ( Plunker ) 似乎有效:

  yAxis: {
tickInterval: 1,
gridLineWidth: 1,
labels: {
formatter: function () {
console.log("scripts.js - yAxis.labels.formatter", this.value);
if (tasks[this.value]) {

//if (tasks[this.value].name === 'LILLY_C') {
var _xAxis = this.chart.axes[0];
var _task = tasks[this.value];
var _show = false;

// Not optimized for large collections
for (var _i = 0; _i < _task.intervals.length; _i++) {
var _int = _task.intervals[_i];
if (_xAxis.min <= _int.to) {
_show = true;
}
}

console.log("scripts.js - yAxis.labels.formatter",
tasks[this.value].name,
_show,
_xAxis.min,
_xAxis.max,
_task.intervals
);

if (_show) {
return tasks[this.value].name;
} else {
return;
}
//}

//return tasks[this.value].name;
}
}
},
startOnTick: false,
endOnTick: false,
title: {
text: 'Task'
}
},

请参阅 Plunker 以获取 demo .

y 轴标签的含义是: 如果您在图表中看到运行或图表右侧有运行,则显示标签。请修改条件

if (_xAxis.min <= _int.to) {

如您所愿。

免责声明:我不使用 Highcharts,所以这个答案试图解释问题,而不是建议解决问题的 Highcharts 方式。


经验教训:

  • yaxis-plugin.js 与问题无关。
  • Highstock.js 是一个 open-source library (highstock.src.js)。如果您调试原始源代码,任何调试都会容易得多。缩小的代码增加了不必要的复杂性和猜测。我已经下载了库并添加了一些 console.log() 以了解发生了什么。

关于javascript - 如何使用范围和导航器功能在 Highcharts 中创建列范围图表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28088958/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com