score:3

Accepted answer

i am assuming you are talking about the tooltip­'s label. in that case, you can set tooltips mode to index in your chart­'s options config, like so :

options: {
      tooltips: {
         mode: 'index'
      },
      ...

ᴡᴏʀᴋɪɴɢ ᴇxᴀᴍᴘʟᴇ ⧩

var ctx = document.getelementbyid('price-history').getcontext('2d');
ctx.height = 150;
var chart = new chart(ctx, {
   type: 'line',
   data: {
      labels: ['jan', 'feb', 'mar', 'apr', 'may'], //<?= json_encode($pricechangedata['labels']); ?>,
      datasets: [{
         label: 'minimali kaina',
         backgroundcolor: 'rgb(64, 127, 178)',
         bordercolor: 'rgb(64, 127, 178)',
         borderwidth: 1,
         data: [3, 1, 4, 2, 5], //<?= json_encode($pricechangedata['line']['price_min']); ?>,
         fill: false
      }, {
         label: 'vidutinė kaina',
         backgroundcolor: '#686868',
         bordercolor: '#686868',
         borderwidth: 1,
         data: [2, 4, 1, 5, 3], //<?= json_encode($pricechangedata['line']['price_avg']); ?>,
         fill: false
      }],
   },
   options: {
      responsive: true,
      tooltips: {
         mode: 'index'
      },
      layout: {
         padding: {
            left: 20,
            right: 15
         }
      },
      scales: {
         xaxes: [{
            display: true,
            scalelabel: {
               display: false,
               labelstring: 'data'
            }
         }],
         yaxes: [{
            display: true,
            stacked: false,
            scalelabel: {
               display: false,
               labelstring: 'kaina'
            }
         }]
      }
   }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.7.0/chart.min.js"></script>
<canvas id="price-history"></canvas>


Related Query

More Query from same tag