Starting with Xojo 2024r4 the Chart feature provides even more control over how DataSets are drawn through new properties on Desktop, Web and iOS. Also, for Desktop, the Chart control adds two new Event handlers to draw the datapoints of the chart in any way you want.
Granular Control on DataSets
The ChartDataset subclasses add three new properties. Now you can choose to allow the interaction from the user (for example when clicking or taping on data points or over a displayed legend in the Chart), you can also choose what legends are visible at the top area of the Chart, as well as choosing to display a Popover when the user moves the mouse over a given rendered datapoint for the associated ChartDataset.
- AllowInteraction: When it is set to False, then the displayed legend for the ChartDataset doesn’t respond to interaction (that is enabling/disabling the associated data in the Chart) or raises the Pressed event for the Chart. Also, it doesn’t fire the Pressed event when the user clicks on any of the rendered data points in the Chart for that particular DataSet.
- IsLegendVisible: When it is set to False, the Legend for the associated ChartDataset is not displayed at the top area of the Chart (always that the Chart.HasLegend property is set to True). This allows a more granular control over the legends that are displayed, so you can have some of the rendered data sets with their legend displayed while others not.
- AllowPopover: When this property is set to False in the ChartDataset, then the Popover won’t be displayed when the user hovers the cursor over any of its rendered points in the Chart.
New Events for Chart on Desktop
Starting with Xojo 2024r4 you can decide how the Chart should draw the data points for any of the rendered ChartDatasets on Desktop. This is done by implementing the two new Event Handlers on the Chart instance:
- DrawPointAt(g As Graphics, x As Double, y As Double, data As ChartDataSet, index As Integer) As Boolean. This event receives from the “g” parameter the graphic context for the datapoint, so you can use any of the available methods and properties of the Graphics class to draw the datapoint. In order to know what datapoint and from what ChartDataset, these are given in the “index” and “data” parameters, respectively. Also, the “x” and “y” parameters receive the coordinates for the top-left corner of the data point to be drawn. These coordinates are relatives to the Chart control instance position. Returning True from this Event means that your code handled the datapoint drawing; otherwise the datapoint will be rendered as usual.
- DrawMouseOverPointAt(g As Graphics, x As Double, y As Double, data As ChartDataSet, index As Integer) As Boolean. This event behaves in the same way as the previous one, the only difference is that it will be raised when the user hovers the cursor over a given datapoint, so you have the chance to decide how to draw the highlighted version of the datapoint.
You can learn more about the Chart control in the Xojo Documentation at: https://documentation.xojo.com/api/user_interface/controls/chart.html#chart
You can learn more about the ChartDataset class (and subclasses) in the Xojo Documentation at: https://documentation.xojo.com/api/user_interface/charts/chartdataset.html#chartdataset
A big thank you for all of you providing feedback and suggestions about how to improve Charts on Xojo! All of these new additions are a direct response from request made from you, so we are happy to make it work the way you need to adhere even more to your needs!
Javier Menendez is an engineer at Xojo and has been using Xojo since 1998. He lives in Castellón, Spain and hosts regular Xojo hangouts en español. Ask Javier questions on Twitter at @XojoES or on the Xojo Forum.