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">
d676c69348c891c2a261a6dbd4f450ddb2e312f3Tripp<p>This example shows how to customize the default tooltip of a `Chart`.</p>
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:
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dl>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>node</dt><dd>Reference to the actual dom node</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>showEvent</dt><dd>Event that should trigger the tooltip</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>hideEvent</dt><dd>Event that should trigger the removal of a tooltip (can be an event or an array of events)</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>styles</dt><dd>A hash of style properties that will be applied to the tooltip node</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>show</dt><dd>Indicates whether or not to show the tooltip</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>markerEventHandler</dt><dd>Displays and hides tooltip based on marker events</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>planarEventHandler</dt><dd>Displays and hides tooltip based on planar events</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>markerLabelFunction</dt><dd>Reference to the function used to format a marker event triggered tooltip's text. The method contains
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp the following arguments:
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dl>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>categoryItem</dt><dd>An object containing the following:
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dl>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>axis</dt><dd>The axis to which the category is bound.</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>displayName</dt><dd>The display name set to the category (defaults to key if not provided).</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>key</dt><dd>The key of the category.</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>value</dt><dd>The value of the category.</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp </dl>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp </dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>valueItem</dt><dd>An object containing the following:
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dl>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>axis</dt><dd>The axis to which the item's series is bound.</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>displayName</dt><dd>The display name of the series. (defaults to key if not provided)</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>key</dt><dd>The key for the series.</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>value</dt><dd>The value for the series item.</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp </dl>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp </dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>itemIndex</dt><dd>The index of the item within the series.</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>series</dt><dd> The `CartesianSeries` instance of the item.</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>seriesIndex</dt><dd>The index of the series in the `seriesCollection`.</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp </dl>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp The method returns an `HTMLElement` which is written into the DOM using `appendChild`. If you override this method and choose to return an html string, you
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp will also need to override the tooltip's `setTextFunction` method to accept an html string.
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp </dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>planarLabelFunction</dt><dd>Reference to the function used to format a planar event triggered tooltip's text
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dl>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>categoryAxis</dt><dd> `CategoryAxis` Reference to the categoryAxis of the chart.
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>valueItems</dt><dd>Array of objects for each series that has a data point in the coordinate plane of the event. Each object contains the following data:
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dl>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>axis</dt><dd>The value axis of the series.</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>key</dt><dd>The key for the series.</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>value</dt><dd>The value for the series item.</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>displayName</dt><dd>The display name of the series. (defaults to key if not provided)</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp </dl>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp </dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>index</dt><dd>The index of the item within its series.</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>seriesArray</dt><dd>Array of series instances for each value item.</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>seriesIndex</dt><dd>The index of the series in the `seriesCollection`.</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp </dl>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp The method returns an `HTMLElement` which is written into the DOM using `appendChild`. If you override this method and choose to return an html string, you
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp will also need to override the tooltip's `setTextFunction` method to accept an html string.
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp </dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>setTextFunction</dt><dd>Method that writes content returned from `planarLabelFunction` or `markerLabelFunction` into the the tooltip node.
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp has the following signature:
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dl>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>label</dt><dd>The `HTMLElement` that the content is to be added.</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp <dt>val</dt><dd>The content to be rendered into tooltip. This can be a `String` or `HTMLElement`. If an HTML string is used, it will be rendered as a
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp string.</dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp </dl>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp </dd>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp</dl>
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp
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 {
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp var msg = document.createElement("div"),
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp underlinedTextBlock = document.createElement("span"),
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp boldTextBlock = document.createElement("div");
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp underlinedTextBlock.style.textDecoration = "underline";
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp boldTextBlock.style.marginTop = "5px";
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp boldTextBlock.style.fontWeight = "bold";
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp underlinedTextBlock.appendChild(document.createTextNode(valueItem.displayName + " for " +
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp categoryItem.axis.get("labelFunction").apply(this, [categoryItem.value, categoryItem.axis.get("labelFormat")])));
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp boldTextBlock.appendChild(document.createTextNode(valueItem.axis.get("labelFunction").apply(this, [valueItem.value, {prefix:"$", decimalPlaces:2}])));
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp msg.appendChild(underlinedTextBlock);
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp msg.appendChild(document.createElement("br"));
9cd4693ce0f719a022c641a0032163bb2c2acbb5Tripp msg.appendChild(boldTextBlock);
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