JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<div id="chartContainer" style="height: 360px; width: 250px;"></div>
CSS
.wordwrap {
white-space: pre-wrap;
}
.canvasjs-chart-tooltip * {
max-width: 200px !important;
}
.canvasjs-chart-tooltip {
left: 250px !important;
/* width: auto; */
}
.custom-tooltip-width {
width: 200px;
}
JavaScript
var toolTipContent = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. ";
var chart = new CanvasJS.Chart("chartContainer",
{
toolTip:{
updated: function(e) {
var width = getToolTipWidth(e.content);
if(width > 199) {
jQuery(".canvasjs-chart-tooltip").addClass("custom-tooltip-width");
jQuery(".canvasjs-chart-tooltip .content").addClass("wordwrap");
} else {
jQuery(".canvasjs-chart-tooltip").removeClass("custom-tooltip-width");
jQuery(".canvasjs-chart-tooltip .content").removeClass("wordwrap");
}
},
content: "<div style='max-width:200px;' class='content'>{customProperty}</div>"
},
data: [
{
type: "column",
dataPoints: [
{ x: 10, y: 25, customProperty: toolTipContent },
{ x: 20, y: 55, customProperty: toolTipContent },
{ x: 30, y: 50, customProperty: toolTipContent },
{ x: 40, y: 65, customProperty: toolTipContent },
{ x: 50, y: 95, customProperty: toolTipContent },
{ x: 60, y: 68, customProperty: toolTipContent },
{ x: 70, y: 28, customProperty: toolTipContent },
{ x: 80, y: 34, customProperty: toolTipContent },
{ x: 90, y: 14, customProperty: toolTipContent }
]
}
]
});
chart.render();
function getToolTipWidth(content) {
var validationDom = document.createElement("div"); // Create a <button> element
validationDom.innerHTML = content;
validationDom.style.display = "inline-block";// Insert text
validationDom.style.maxWidth = "200px";// Insert text
document.body.appendChild(validationDom);
toolTipWidth =...