charts-customizedtooltip.mustache revision 2431f6aca1be7f7a136c5df34022e3f902490075
2431f6aca1be7f7a136c5df34022e3f902490075Tripp<style scoped>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp#mychart {
2431f6aca1be7f7a136c5df34022e3f902490075Tripp margin:10px 10px 10px 10px;
2431f6aca1be7f7a136c5df34022e3f902490075Tripp width:90%;
2431f6aca1be7f7a136c5df34022e3f902490075Tripp max-width: 800px;
2431f6aca1be7f7a136c5df34022e3f902490075Tripp height:400px;
2431f6aca1be7f7a136c5df34022e3f902490075Tripp}
2431f6aca1be7f7a136c5df34022e3f902490075Tripp</style>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp<div class="intro">
2431f6aca1be7f7a136c5df34022e3f902490075TrippThis example shows how to customize the default tooltip of a `Chart`.
2431f6aca1be7f7a136c5df34022e3f902490075Tripp</div>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp<div class="example">
2431f6aca1be7f7a136c5df34022e3f902490075Tripp{{>charts-customizedtooltip-source}}
2431f6aca1be7f7a136c5df34022e3f902490075Tripp</div>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp
2431f6aca1be7f7a136c5df34022e3f902490075Tripp<h3>This example shows how to customize the tooltip for a `Chart`.</h3>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp
2431f6aca1be7f7a136c5df34022e3f902490075Tripp<p>A `Chart` instance comes with a simple default tooltip. This tooltip is represented by the `tooltip` attribute. Through the tooltip attribute you can do the following:
2431f6aca1be7f7a136c5df34022e3f902490075Tripp<ul>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp <li>Style the tooltip background, border and text.</li>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp <li>Customize and format the tooltip message.</li>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp <li>Change the show and hide events.</li>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp <li>Disable the tooltip.</li>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp</ul>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp</p>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp<p>The `tooltip` attribute contains the following properties:
2431f6aca1be7f7a136c5df34022e3f902490075Tripp <ul>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp <li>showEvent: event that should trigger the tooltip</li>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp <li>hideEvent: event that should trigger the removal of a tooltip (can be an event or an array of events)</li>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp <li>styles: hash of style properties that will be applied to the tooltip node</li>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp <li>show: indicates whether or not to show the tooltip</li>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp <li>markerEventHandler: displays and hides tooltip based on marker events</li>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp <li>planarEventHandler: displays and hides tooltip based on planar events</li>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp <li>markerLabelFunction: reference to the function used to format a marker event triggered tooltip's text</li>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp <li>planarLabelFunction: reference to the function used to format a planar event triggered tooltip's text</li>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp </ul>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp</p>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp<p>In this example, we have changed the styles and set a custom `markerLabelFunction` to format the text.</p>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp```
2431f6aca1be7f7a136c5df34022e3f902490075Trippvar myDataValues = [
2431f6aca1be7f7a136c5df34022e3f902490075Tripp {category:"5/1/2010", Miscellaneous:2000, Expenses:3700, Revenue:2200},
2431f6aca1be7f7a136c5df34022e3f902490075Tripp {category:"5/2/2010", Miscellaneous:50, Expenses:9100, Revenue:100},
2431f6aca1be7f7a136c5df34022e3f902490075Tripp {category:"5/3/2010", Miscellaneous:400, Expenses:1100, Revenue:1500},
2431f6aca1be7f7a136c5df34022e3f902490075Tripp {category:"5/4/2010", Miscellaneous:200, Expenses:1900, Revenue:2800},
2431f6aca1be7f7a136c5df34022e3f902490075Tripp {category:"5/5/2010", Miscellaneous:5000, Expenses:5000, Revenue:2650}
2431f6aca1be7f7a136c5df34022e3f902490075Tripp];
2431f6aca1be7f7a136c5df34022e3f902490075Tripp
2431f6aca1be7f7a136c5df34022e3f902490075Trippvar myTooltip = {
2431f6aca1be7f7a136c5df34022e3f902490075Tripp styles: {
2431f6aca1be7f7a136c5df34022e3f902490075Tripp backgroundColor: "#333",
2431f6aca1be7f7a136c5df34022e3f902490075Tripp color: "#eee",
2431f6aca1be7f7a136c5df34022e3f902490075Tripp borderColor: "#fff",
2431f6aca1be7f7a136c5df34022e3f902490075Tripp textAlign: "center"
2431f6aca1be7f7a136c5df34022e3f902490075Tripp },
2431f6aca1be7f7a136c5df34022e3f902490075Tripp markerLabelFunction: function(categoryItem, valueItem, itemIndex, series, seriesIndex)
2431f6aca1be7f7a136c5df34022e3f902490075Tripp {
2431f6aca1be7f7a136c5df34022e3f902490075Tripp var msg = "<span style=\"text-decoration:underline\">" + valueItem.displayName + " for " +
2431f6aca1be7f7a136c5df34022e3f902490075Tripp categoryItem.axis.get("labelFunction").apply(this, [categoryItem.value, categoryItem.axis.get("labelFormat")]) +
2431f6aca1be7f7a136c5df34022e3f902490075Tripp "</span><br/><div style=\"margin-top:5px;font-weight:bold\">" + valueItem.axis.get("labelFunction").apply(this, [valueItem.value, {prefix:"$", decimalPlaces:2}]) + "</div>";
2431f6aca1be7f7a136c5df34022e3f902490075Tripp return msg;
2431f6aca1be7f7a136c5df34022e3f902490075Tripp }
2431f6aca1be7f7a136c5df34022e3f902490075Tripp};
2431f6aca1be7f7a136c5df34022e3f902490075Tripp
2431f6aca1be7f7a136c5df34022e3f902490075Trippvar mychart = new Y.Chart({
2431f6aca1be7f7a136c5df34022e3f902490075Tripp dataProvider:myDataValues,
2431f6aca1be7f7a136c5df34022e3f902490075Tripp type:"bar",
2431f6aca1be7f7a136c5df34022e3f902490075Tripp render:"#mychart",
2431f6aca1be7f7a136c5df34022e3f902490075Tripp tooltip: myTooltip
2431f6aca1be7f7a136c5df34022e3f902490075Tripp });
2431f6aca1be7f7a136c5df34022e3f902490075Tripp```
2431f6aca1be7f7a136c5df34022e3f902490075Tripp