Platforms to show: All Mac Windows Linux Cross-Platform

Required plugins for this example: MBS ChartDirector Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /ChartDirector/heatmapcelllabels
This example is the version from Thu, 28th Apr 2021.
Project "heatmapcelllabels.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
EventHandler Sub Open() CDBaseChartMBS.ScaleFactor = 2 // The x-axis and y-axis labels Dim xLabels() As String = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J") Dim xLabels_size As Integer = xLabels.Ubound + 1 Dim yLabels() As String = Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9") Dim yLabels_size As Integer = yLabels.Ubound + 1 // Random data for the 10 x 10 cells Dim rand As New CDRanSeriesMBS(2) Dim zData() As Double = rand.get2DSeries(xLabels_size, yLabels_size, 0, 100) // We set the middle 5 x 5 cells to NoValue to remove them from the chart For x As Integer = 3 To 6 For y As Integer = 3 To 6 zData(y * xLabels_size + x) = CDBaseChartMBS.kNoValue Next Next // Create an XYChart object of size 480 x 540 pixels. Dim c As New CDXYChartMBS(480, 540) // Set the plotarea at (50, 40) and of size 400 x 400 pixels. Set the background, border, and // grid lines to transparent. Dim p As CDPlotAreaMBS = c.setPlotArea(50, 40, 400, 400, -1, -1, CDBaseChartMBS.kTransparent, CDBaseChartMBS.kTransparent) // Create a discrete heat map with 10 x 10 cells Dim layer As CDDiscreteHeatMapLayerMBS = c.addDiscreteHeatMapLayer(zData, xLabels_size) // Set the x-axis labels. Use 8pt Arial Bold font. Set axis stem to transparent, so only the // labels are visible. Set 0.5 offset to position the labels in between the grid lines. Position // the x-axis at the top of the chart. Call c.xAxis.setLabels(xLabels) Call c.xAxis.setLabelStyle("Arial Bold", 8) c.xAxis.setColors(CDBaseChartMBS.kTransparent, CDBaseChartMBS.kTextColor) c.xAxis.setLabelOffset(0.5) Call c.xAxis.setTitle("X axis title placeholder", "Arial Bold", 12) c.setXAxisOnTop // Set the y-axis labels. Use 8pt Arial Bold font. Set axis stem to transparent, so only the // labels are visible. Set 0.5 offset to position the labels in between the grid lines. Reverse // the y-axis so that the labels are flowing top-down instead of bottom-up. Call c.yAxis.setLabels(yLabels) Call c.yAxis.setLabelStyle("Arial Bold", 8) c.yAxis.setColors(CDBaseChartMBS.kTransparent, CDBaseChartMBS.kTextColor) c.yAxis.setLabelOffset(0.5) Call c.yAxis.setTitle("Y axis title placeholder", "Arial Bold", 12) c.yAxis.setReverse // Set a 3-pixel gap between cells layer.setCellGap(3) // Use the z value as the cell label layer.setDataLabelFormat("{z|0}") // Position the color axis 20 pixels below the plot area and of the width as the plot area. Put // the labels at the bottom side of the color axis. Use 8pt Arial Bold font for the labels. Dim cAxis As CDColorAxisMBS = layer.setColorAxis(p.getLeftX, p.getBottomY + 20, CDBaseChartMBS.kTopLeft, p.getWidth, CDBaseChartMBS.kBottom) Call cAxis.setLabelStyle("Arial Bold", 8) Call cAxis.setTitle("Color legend title placeholder", "Arial Bold", 12) // Set the color stops and scale of the color axis Dim colorScale() As Double = Array(0.0, &h00ff00, 50, &hffff00, 80, &hff6600, 100, &hff0000) cAxis.setColorScale(colorScale) cAxis.setLinearScale(0, 100, 10) // Output the chart pic = c.makeChartPicture // drawn in paint event End EventHandler
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) If pic <> Nil Then // scale to window g.DrawPicture pic, 0, 0, g.Width, g.Height, 0, 0, pic.Width, pic.Height End If End EventHandler
Property pic As Picture
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS ChartDirector Plugin.

The biggest plugin in space...

MBS Xojo blog

Start Chat