Example: /ChartDirector/posnegwaterfall

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

Platforms to show: All Mac Windows Linux Cross-Platform

/ChartDirector/posnegwaterfall


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/posnegwaterfall

This example is the version from Sun, 17th Mar 2012.

Project "posnegwaterfall.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() // 4 data points to represent the cash flow for the Q1 - Q4 dim data(-1) as double = array(230, -140, 220, 330.0) // We want to plot a waterfall chart showing the 4 quarters as well as the total dim labels(-1) as string = array("1st Quarter", "2nd Quarter", "3rd Quarter", "4th Quarter", "Total") // The top side of the bars in a waterfall chart is the accumulated data. We use // the ChartDirector ArrayMath utility to accumulate the data. The "total" is // handled by inserting a zero point at the end before accumulation (after // accumulation it will become the total). dim boxTop as new CDArrayMBS(data) boxtop.insert(0, 1, 4) boxtop.acc // The botom side of the bars is just the top side of the previous bar. So we // shifted the top side data to obtain the bottom side data. dim boxBottom as new CDArrayMBS(boxTop) boxbottom.shift(1, 0) // The last point (total) is different. Its bottom side is always 0. boxBottom.trim(0, 4) boxBottom.insert(0, 1) // In this example, we want to use different colors depending on the data is // positive or negative. dim posColor as integer = &h00ff00 dim negColor as integer = &hff0000 // Create a XYChart object of size 500 x 280 pixels. Set background color to // light blue (ccccff), with 1 pixel 3D border effect. dim c as new CDXYChartMBS(500, 300, &hccccff, &h000000, 1) // Add a title to the chart using 13 points Arial Bold Itatic font, with white // (ffffff) text on a deep blue (&h80) background c.addTitle("Corporate Cash Flow - Year 2004", "arialbi.ttf", 13, &hffffff).setBackground(&h000080) // Set the plotarea at (55, 50) and of size 430 x 215 pixels. Use alternative // white/grey background. call c.setPlotArea(55, 50, 430, 215, &hffffff, &heeeeee) // Add a legend box at (55, 25) using 8 pts Arial Bold font with horizontal // layout, with transparent background and border color. dim b as CDLegendBoxMBS b = c.addLegend(55, 25, false, "arialbd.ttf", 8) b.setBackground(c.kTransparent, c.kTransparent) // Add keys to show the colors for positive and negative cash flows b.addKey("Positive Cash Flow", posColor) b.addKey("Negative Cash Flow", negColor) // Set the labels on the x axis using Arial Bold font c.xAxis.setLabels(labels).setFontStyle("arialbd.ttf") // Set the x-axis ticks and grid lines to be between the bars c.xAxis.setTickOffset(0.5) // Use Arial Bold as the y axis label font call c.yAxis.setLabelStyle("arialbd.ttf") // Add a title to the y axis call c.yAxis.setTitle("USD (in millions)") dim bTop(-1) as Double dim bBottom(-1) as Double dim i,count as integer count=boxtop.count-1 for i=0 to count btop.append boxtop.getvalue(i) next count=boxbottom.count-1 for i=0 to count bbottom.append boxbottom.getvalue(i) next // Add a box-whisker layer to represent the waterfall bars dim layer as CDBoxWhiskerLayerMBS layer = c.addBoxWhiskerLayer(bTop, bBottom) for i=0 to boxTop.count-1 if (boxTop.getvalue(i) >= boxBottom.getvalue(i)) then call layer.setBoxColor(i, posColor) else call layer.setBoxColor(i, negColor) end if next // Put data labels on the bars to show the cash flow using Arial Bold font layer.setDataLabelFormat("{={top}-{bottom}}M") layer.setDataLabelStyle("arialbd.ttf").setAlignment(c.kCenter) // Output the chart 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

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


💬 Ask a question or report a problem