You can create a custom right-click menu in any chart. By default, when the viewer clicks the right mouse button, he gets default Flash player menu. You can disable default menu items or add some custom ones. You can use this feature to create some controls for your chart. For example, right-click on this chart. Instead of default menu items, you will see three custom ones: 10 years, 20 years and Show full. Click on one of them and you will see that the chart changes the selected period.
When you select the menu item, a JavaScript function is called. In this case, this function controls the selected period.
The right-click menu is controlled in the settings file, <context_menu> section. These are the settings of the example mentioned above:
<context_menu> <menu function_name="selectInterval(10)" title="10 years"></menu> <menu function_name="selectInterval(20)" title="20 years"></menu> <menu function_name="showAll" title="Show full"></menu> <default_items> <zoom>false</zoom> <print>false</print> </default_items> </context_menu>
As you see, there are three <menu> items added. You can have any number of them. The "title" attribute defines the menu item name and the "function_name" attribute defines the JavaScript function, which will be called when the user clicks on this menu item. If you view the source of the example page, you will find the "selectInterval" and "showAll" JavaScript functions there. The full JavaScript part required for this right click menu to work is as follows:
<script type="text/javascript"> function amChartInited (chart_id){ flashMovie = document.getElementById("amline"); } function selectInterval(interval){ flashMovie.setZoom(2006 - interval, 2006); } function showAll(){ flashMovie.showAll(); } </script>
Important: You can't use menu item names that are already in the default Flash player right-click menu: Zoom In, Zoom Out, Show All, Print and Settings.
You can't hide the "Settings" and "About Adobe Flash Player X" menu items.
| © Antanas Marcelionis Contact and feedback: info@amcharts.com | Subscribe to amCharts news |