Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.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
Javascript AMSCHARTS工具提示仅显示在DateAxis上,而不显示ValueAxis_Javascript_Html_Json_Charts_Amcharts - Fatal编程技术网

Javascript AMSCHARTS工具提示仅显示在DateAxis上,而不显示ValueAxis

Javascript AMSCHARTS工具提示仅显示在DateAxis上,而不显示ValueAxis,javascript,html,json,charts,amcharts,Javascript,Html,Json,Charts,Amcharts,我正在使用amCharts,我正在制作一个包含多个系列的XY图表,当X轴类型为DateAxis时,工具提示仅显示ony,但当它为ValueAxis var dateAxis = chart5.xAxes.push(new am4charts.DateAxis()); series.dataFields.dateX = "time"; 带工具提示的图表: 现在,当我将这两条线更改为值轴时,它不起作用 var dateAxis = chart5.xAxes.push(new am4charts.

我正在使用amCharts,我正在制作一个包含多个系列的XY图表,当X轴类型为
DateAxis
时,工具提示仅显示ony,但当它为
ValueAxis

var dateAxis = chart5.xAxes.push(new am4charts.DateAxis());
series.dataFields.dateX = "time";
带工具提示的图表:

现在,当我将这两条线更改为值轴时,它不起作用

var dateAxis = chart5.xAxes.push(new am4charts.ValueAxis());
    series.dataFields.valueX = "time";
无工具提示的图表:


以下是对@xorspark发布此类示例(我也遇到过)请求的回复:

XY图表,Y轴为ValueAxis,X轴为CategoryAxis。。。。工具提示也可以工作:

相同的XY图表,但X轴已从CategoryAxis更改为ValueAxis。。。工具提示也不见了:

两者之间的变化仅为3行:

var theXAxis = chart.xAxes.push(new am4charts.CategoryAxis());
theXAxis.dataFields.category = "xValue";
变成

var theXAxis = chart.xAxes.push(new am4charts.ValueAxis());
series1.dataFields.valueX = "xValue";

变成

var theXAxis = chart.xAxes.push(new am4charts.ValueAxis());
series1.dataFields.valueX = "xValue";

也许我们都没有正确阅读文档中的内容?如果是这样的话,我就不知道是什么了。或者也许。。。工具提示在X-ValueAxis和Y-ValueAxis图表中是否被破坏或不受支持?

我遇到了同样的问题,深入研究后,我意识到ValueAxis没有实现方法(而且确实如此)。所以,我的解决方案就是实现这个方法。基于其他axis实现,我给出的代码是:

am4charts.ValueAxis.prototype.getSeriesDataItem = function (series, position) {
    var key = this.axisFieldName + this.axisLetter;
    var value = this.positionToValue(position);
    return series.dataItems.getIndex(series.dataItems.findClosestIndex(value, function(x) {
        return x[key];
    }, "any"));
}
添加此原型后,工具提示在使用ValueAxis时不会出现问题:

/*******修复:将getSeriesDataItem方法添加到ValueAxis************/
am4charts.ValueAxis.prototype.getSeriesDataItem=函数(系列,位置){
var key=this.axisFieldName+this.axisLetter;
var值=此.positionToValue(位置);
return series.dataItems.getIndex(series.dataItems.findclosestinex)值,函数(x){
返回x[键];
}(“任何”);
}
/**********************************************************************/
/*创建图表实例*/
var chart=am4core.create(“chartdiv”,am4charts.XYChart);
/*添加数据*/
chart.data=[{
“xValue”:1000,
“yValue”:1587
}, {
“xValue”:1100,
“yValue”:1567
}, {
“xValue”:1250,
“yValue”:1617
}, {
“xValue”:1400,
“yValue”:1630
}, {
“xValue”:1700,
“yValue”:1660
}, {
“xValue”:1754年,
“yValue”:1683
}, {
“xValue”:2255,
“yValue”:1691
}, {
“xValue”:3004,
“yValue”:1298
}];
/*创建轴*/
var theXAxis=chart.xAxes.push(新的am4charts.ValueAxis());
/*创造价值轴*/
var theYAxis=chart.yAxes.push(新的am4charts.ValueAxis());
/*创建系列*/
var series1=chart.series.push(新的am4charts.LineSeries());
series1.dataFields.valueY=“yValue”;
series1.dataFields.valueX=“xValue”;
series1.name=“X轴”;
系列1.子弹。推(新am4charts.CircleBullet());
series1.tooltipText=“{valueY}”;
/*添加图例*/
chart.legend=新的am4charts.legend();
/*创建光标*/
chart.cursor=新的am4charts.XYCursor()
正文{
字体系列:-苹果系统、BlinkMacSystemFont、“Segoe UI”、Roboto、Helvetica、Arial、无衬线、“苹果颜色表情”、“Segoe UI表情”、“Segoe UI符号”;
}
#沙特迪夫{
宽度:100%;
高度:300px;
}

请发布您的其余代码,最好是作为小提琴或可运行的演示。