Search code examples
javascripttooltipanychart

tooltipFormat doesn't work for anychart.line()


I found an interesting bug I guess...

If I create a lineChart and want to change the Tooltip Title with a format, it does not work.

chart = anychart.line();
var seriesData_1 = dataSet.mapAs({x: [0], value: [1]});
series_1 = chart.line(seriesData_1);

chart.tooltip().titleFormat('{%x}'); //works
chart.tooltip().titleFormat('{%value}');  //does not work

I'm on AnyChart Version: Version: 7.14.3.1436


Solution

  • This is not an unexpected behavior or a bug. The thing is the line chart provides union displayMode for tooltips as a default. In this case tooltip body related to series, but the title to the chart which is a common thing for all series. So, to achieve your aim you should switch displayMode to 'separated' or 'single'. Please, check a sample below for details

    anychart.onDocumentReady(function () {
      
        var dataSet = anychart.data.set([['1', 10],
                        				  ['2',12]]);
      
    chart = anychart.line();
      var seriesData_1 = dataSet.mapAs({x: 0, value: 1});
      
    	series_1 = chart.line(seriesData_1);
      
      var tooltip = chart.tooltip();
      tooltip.displayMode('single');
      tooltip.titleFormat("value: {%value}");
      
      
        chart.container("container").draw();
    });
    html, body, #container {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
    }
    <link href="https://cdn.anychart.com/css/7.14.3/anychart-ui.min.css" rel="stylesheet"/>
    <script src="https://cdn.anychart.com/js/8.1.0/anychart-bundle.min.js"></script>
    <div id="container"></div>