Platforms to show: All Mac Windows Linux Cross-Platform
/ChartDirector/discreteheatmap
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/discreteheatmap
This example is the version from Fri, 9th Feb 2023.
Project "discreteheatmap.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 r As New CDRanSeriesMBS(2)
Dim zData() As Double = r.get2DSeries(xLabels_size, yLabels_size, 0, 100)
// Create an XYChart object of size 520 x 470 pixels.
Dim c As New CDXYChartMBS(520, 470)
// Set the plotarea at (50, 30) and of size 400 x 400 pixels.
Dim p As CDPlotAreaMBS = c.setPlotArea(50, 30, 400, 400)
// 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.
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)
// 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.
Call c.yAxis.setLabels(yLabels)
Call c.yAxis.setLabelStyle("Arial Bold", 8)
Call c.yAxis.setColors(CDBaseChartMBS.kTransparent, CDBaseChartMBS.kTextColor)
c.yAxis.setLabelOffset(0.5)
Call c.yAxis.setTitle("Y Axis Title Placeholder", "Arial Bold", 12)
// Position the color axis 20 pixels to the right of the plot area and of the same height as the
// plot area. Put the labels on the right side of the color axis. Use 8pt Arial Bold font for
// the labels.
Dim cAxis As CDColorAxisMBS = layer.setColorAxis(p.getRightX + 20, p.getTopY, CDBaseChartMBS.kTopLeft, p.getHeight, CDBaseChartMBS.kRight)
Call cAxis.setLabelStyle("Arial Bold", 8)
// double everything for bitmap output for HiDPI display
c.setOutputOptions("bmpscale=2")
// alternartive way
'c.setOutputOptions("dpi=192")
// Output the chart
pic = c.makeChartPicture
Title = Str(pic.Width)
// 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
The items on this page are in the following plugins: MBS ChartDirector Plugin.