amCharts-XY图表工具提示和项目符号

时间:2019-08-30 17:53:28

标签: amcharts

我在amCharts 4中有一个XY图表,并且无法设置正确的参数以插入到工具提示中。这是设计图表的代码:

是否可以在工具提示中显示参数“ desc”?

var chart = am4core.create("chartdiv", am4charts.XYChart);

// Add data
chart.data = [ {
    "x": -6,
    "y": 0,
    "diam": 4,
    "desc": "test"
  }, {
    "x": 0,
    "y": -10,
    "diam": 4,
    "desc": "test"
  }, {
    "x": 12,
    "y": 10,
    "diam": 8,
    "desc": "special"
  } ];

// Create axes
var xAxis = chart.xAxes.push(new am4charts.ValueAxis());

var yAxis = chart.yAxes.push(new am4charts.ValueAxis());

// Create series
var series = chart.series.push(new am4charts.LineSeries());
series.dataFields.valueX = "x";
series.dataFields.valueY = "y";
series.strokeWidth = 2;
series.fillOpacity = 0;
series.stroke = "red";

// Create bullet and tooltip
seriesBullet = series.bullets.push(new am4charts.CircleBullet());
seriesBullet.circle.fill = am4core.color("#fff");
seriesBullet.circle.strokeWidth = 3;
seriesBullet.circle.propertyFields.radius = "diam";
seriesBullet.tooltipText = "desc";
#chartdiv {
  width: 100%;
  height: 200px;
}
<script src="https://www.amcharts.com/lib/4/core.js"></script>
<script src="https://www.amcharts.com/lib/4/charts.js"></script>
<div id="chartdiv"></div>

2 个答案:

答案 0 :(得分:1)

您需要将CreateDefaultBuilder用大括号括起来:desc

{desc}

这是您更新后的工作示例:

seriesBullet.tooltipText = "{desc}";
var chart = am4core.create("chartdiv", am4charts.XYChart);

// Add data
chart.data = [ {
    "x": -6,
    "y": 0,
    "diam": 4,
    "desc": "test"
  }, {
    "x": 0,
    "y": -10,
    "diam": 4,
    "desc": "test"
  }, {
    "x": 12,
    "y": 10,
    "diam": 8,
    "desc": "special"
  } ];

// Create axes
var xAxis = chart.xAxes.push(new am4charts.ValueAxis());

var yAxis = chart.yAxes.push(new am4charts.ValueAxis());

// Create series
var series = chart.series.push(new am4charts.LineSeries());
series.dataFields.valueX = "x";
series.dataFields.valueY = "y";
series.strokeWidth = 2;
series.fillOpacity = 0;
series.stroke = "red";
series.tooltipText = "{desc}";

// Create bullet and tooltip
seriesBullet = series.bullets.push(new am4charts.CircleBullet());
seriesBullet.circle.fill = am4core.color("#fff");
seriesBullet.circle.strokeWidth = 3;
seriesBullet.circle.propertyFields.radius = "diam";
seriesBullet.tooltipText = "{desc}";
#chartdiv {
  width: 100%;
  height: 200px;
}

答案 1 :(得分:0)

您需要将参数放在{}大括号内。 例如:

seriesBullet.tooltipText = "{desc}";