Platforms to show: All Mac Windows Linux Cross-Platform

/ChartDirector/posnegbar middle


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/posnegbar middle

This example is the version from Fri, 13th Dec 2012.

Project "posnegbar middle.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class PicWindow Inherits Window
EventHandler Sub Open() // The data for the bar chart dim data(-1) as double = array( 4.3, 2.3, 0.7, 3.4, 2.2, 2.9, 0.1, 0.1, 3.3, 2.2, 4.3, 1.6) // The labels for the bar chart dim labels(-1) as string = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec") // Create a XYChart object of size 500 x 320 pixels dim c as new CDXYChartMBS(500, 320) // Add a title to the chart using Arial Bold Italic font call c.addTitle("Productivity Change - Year 2005", "arialbi.ttf") // Set the plotarea at (50, 30) and of size 400 x 250 pixels call c.setPlotArea(50, 30, 400, 250) // Add a bar layer to the chart using the Overlay data combine method dim layer as CDBarLayerMBS layer = c.addBarLayer(c.kOverlay) // Select positive data and add it as data set with blue (6666ff) color dim d(-1) as Double dim i,count as integer count=UBound(data) for i=0 to count if data(i)>=2.5 then d.append data(i) else d.append c.knoValue end if next call layer.addDataSet(d, &h6666ff) redim d(-1) count=UBound(data) for i=0 to count if data(i)<2.5 then d.append data(i) else d.append c.knoValue end if next 'A transparent axis of which the y = 0 is in the middle Call c.yAxis.setLinearScale(-1, 1, 2) Call c.yAxis.setColors(c.kTransparent, c.kTransparent, c.kTransparent, c.kTransparent) c.yAxis.setLabelFormat(" ") 'Now the x-axis can be put in the middle Call c.setAxisAtOrigin(c.kXAxisAtOrigin) // Select negative data and add it as data set with orange (ff6600) color call layer.addDataSet(d, &hff6600) // Add labels to the top of the bar using 8 pt Arial Bold font. The font color is // configured to be red (0xcc3300) below zero, and blue (0x3333ff) above zero. call layer.setAggregateLabelStyle("arialbd.ttf", 8, layer.yZoneColor(2.5, &hcc3300, &h3333ff)) Call Layer.setUseYAxis2() // Set the labels on the x axis and use Arial Bold as the label font dim t as CDTextBoxMBS t=c.xAxis.setLabels(labels) t.setFontStyle("arialbd.ttf") // Draw the y axis on the right of the plot area c.setYAxisOnRight(true) // Use Arial Bold as the y axis label font call c.yAxis2.setLabelStyle("arialbd.ttf") // Add a title to the y axis call c.yAxis2.setTitle("Percentage") // Add a light blue (0xccccff) zone for positive part of the plot area call c.yAxis2.addZone(2.5, 9999, &hccccff) // Add a pink (0xffffcc) zone for negative part of the plot area call c.yAxis2.addZone(-9999, 2.5, &hffcccc) 'Put the transparent y-axis on right, and so the yAxis2 will be on the left side Call c.setYAxisOnRight() 'Use the secondary y-axis for the grid lines Call c.getPlotArea().setGridAxis(c.xAxis(), c.yAxis2()) Backdrop=c.makeChartPicture End EventHandler
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
End Project

See also:

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


The biggest plugin in space...