javascript - 不知道如何实现范围到 amcharts
问题描述
我正在使用 amcharts 插件来创建漂亮的图表。我发现了一些要添加范围的东西,但是图表代码的结构与我的不同,我似乎无法找到如何用我的代码来实现它。这是我设置图表的方式。
var chartConfig = {
"type": "serial",
"theme": "none",
"marginLeft": 70,
"dataDateFormat": "YYYY-MM-DD",
"graphs": [{
"bullet": "round",
"bulletBorderAlpha": 1,
"bulletColor": "#FFFFFF",
"bulletSize": 5,
"hideBulletsCount": 50,
"lineThickness": 2,
"title": "red line",
"useLineColorForBulletBorder": true,
"valueField": "value"
}],
"chartCursor": {
"categoryBalloonEnabled": false
},
"categoryField": "date",
"categoryAxis": {
"parseDates": true,
"dashLength": 1,
"minorGridEnabled": true,
"labelsEnabled": false,
"tickLength": 0
},
"valueAxes": [{
"ignoreAxisWidth": true
}],
var charts = [];
charts.push(AmCharts.makeChart("chartdiv", chartConfig));
charts.push(AmCharts.makeChart("chartdiv2", chartConfig2));
charts.push(AmCharts.makeChart("chartdiv3", chartConfig3));
for (var x in charts) {
charts[x].addListener("zoomed", syncZoom);
charts[x].addListener("init", addCursorListeners);
}
function addCursorListeners(event) {
event.chart.chartCursor.addListener("changed", handleCursorChange);
event.chart.chartCursor.addListener("onHideCursor", handleHideCursor);
}
function syncZoom(event) {
for (x in charts) {
if (charts[x].ignoreZoom) {
charts[x].ignoreZoom = false;
}
if (event.chart != charts[x]) {
charts[x].ignoreZoom = true;
charts[x].zoomToDates(event.startDate, event.endDate);
}
}
}
function handleCursorChange(event) {
for (var x in charts) {
if (event.chart != charts[x]) {
charts[x].chartCursor.syncWithCursor(event.chart.chartCursor);
}
}
}
function handleHideCursor() {
for (var x in charts) {
if (charts[x].chartCursor.hideCursor) {
charts[x].chartCursor.forceShow = false;
charts[x].chartCursor.hideCursor(false);
}
}
}
有人知道如何在我的情况下实现范围吗?提前致谢!
解决方案
由于您使用的是 v3,因此我假设您指的是guides。轴范围是一个 v4 功能,可以完成同样的事情。
通过指定起点/终点、填充、线条颜色和可选文本,可以将指南添加到图表对象。如果您在类别轴上绘制指南,请使用date
/toDate
或category
/ toCategory
。如果您在值轴上绘制指南,请使用value
/ toValue
:
guides: [{
//date-based category axis guide
date: "2019-02-20",
toDate: "2019-02-22",
fillAlpha: .20,
fillColor: "#ee7d01",
label: "Category Axis guide",
inside: true //move label inside instead of displaying it on the axis
}, {
//value axis guide
value: 10,
toValue: 30,
fillAlpha: .20,
fillColor: "#10d7ee",
label: "Value Axis guide",
inside: false //keep label outside along the axis
}]
推荐阅读
- python - 如何解释 scikit-survial 的结果?
- python - 如何从字符串列表中删除字符的所有实例?
- c++ - 如何将度数转换为弧度?
- python - python:Auto-Py-To-Exe 生成的 exe 导致错误“Fatal Error Failed to execute app”
- php - Http 客户端 laravel
- flutter - 解析 pubspec.yaml 中的块映射错误时需要一个密钥
- search - 使用来自另一个单元格的部分字符串搜索谷歌表格中的范围?
- c - C中的printf语句修改
- c# - 静态字段变量初始化器在在线编译器中失败,但在 VS 中有效
- docker - 磁盘空间不足异常 - 基于 docker 容器的 Nexus