0

I want to display two values(Amount, paid status) in the tooltip when the user hovers display Bar Dataset and Line Dataset based on the month. currently, it's displaying a BarDataset value

let amount= [500, 2000, 1400, 900];
let paidStatus = ["Unpaid", "Paid", "Unpaid","Paid"];
let Months = ['January', 'February', 'March', 'April'];
let myChart = document.getElementById('myChart').getContext('2d');

let massPopChart = new Chart(myChart, {
 type: 'bar',
data: {
    datasets: [{
        label: 'Bar Dataset',
        data: amount
    }, {
        label: 'Line Dataset',
        data: paidStatus,

        // Changes this dataset to become a line
        type: 'line'
    }],
    labels: Months
},
options: {
  tooltips: {
  mode: 'index'
}
}
});`
2
  • I run your code but and see that no line appears in your chart because the values of the corresponding dataset are non-numeric. Therefore I cannot exactly understand what you're looking for. Please elaborate. Commented Jul 14, 2020 at 15:38
  • @uminder I update the question. basically I want to display the amount, status in the tooltip Commented Jul 14, 2020 at 17:59

1 Answer 1

1

You might want to try representing the "paid status" as a numeric (0-unpaid, 1-paid) then use a callback to customize the tooltip:

function(tooltipItems, data) {
   var y = tooltipItems.yLabel;
    if(tooltipItems.datasetIndex === 1) {
      tooltipItems.yLabel === 0 ? y = 'unpaid' : y = 'paid'
    }
    return y
  }
}

jsfiddle

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.