Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/ChartDirector/symbolline datezoom
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /ChartDirector/symbolline datezoom
This example is the version from Mon, 5th May 2019.
Project "symbolline datezoom.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class PicWindow Inherits Window
Const zoomInRatio = 2.0
Const zoomOutRatio = 0.5
Control out Inherits Canvas
ControlInstance out Inherits Canvas
EventHandler Function MouseDown(X As Integer, Y As Integer) As Boolean if ToolMove.Value then out.MouseCursor=System.Cursors.HandClosed StartX=X StartY=Y viewport.startDrag else // zoom StartX=X StartY=Y StartX2=X StartY2=Y end if Return true End EventHandler
EventHandler Sub MouseDrag(X As Integer, Y As Integer) if ToolMove.Value then if viewport.dragTo(CDBaseChartMBS.kDirectionHorizontalVertical, Startx-x,y-Starty) then redraw end if else StartX2=X StartY2=Y dim l,t as integer dim w,h as integer l=min(StartX,StartX2) t=min(StartY,StartY2) w=StartX2-StartX h=StartY2-StartY if w<0 then w=-w if h<0 then h=-h out.Graphics.DrawPicture lastpicture,0,0 out.Graphics.DrawPicture rectanglePicture, l, t, w, h, 0, 0, rectanglePicture.Width, rectanglePicture.Height end if End EventHandler
EventHandler Sub MouseUp(X As Integer, Y As Integer) if ToolMove.Value then out.MouseCursor=System.Cursors.HandOpen elseif ToolZoomIn.Value then // zoom on point? if abs(X-StartX)<3 and abs(Y-StartY)<3 then // zoom in on point if viewport.canZoomIn(CDBaseChartMBS.kDirectionHorizontalVertical) then if viewport.zoomAt(CDBaseChartMBS.kDirectionHorizontalVertical, x, y, zoomInRatio) then redraw end if else redraw beep end if else // zoom in on a rectangle if viewport.canZoomIn(CDBaseChartMBS.kDirectionHorizontalVertical) then if viewport.zoomTo(CDBaseChartMBS.kDirectionHorizontalVertical, x, y, StartX, StartY) then redraw end if else redraw beep end if end if elseif ToolZoomOut.Value then // zoom out on point if viewport.canZoomOut(CDBaseChartMBS.kDirectionHorizontalVertical) then if viewport.zoomAt(CDBaseChartMBS.kDirectionHorizontalVertical, x, y, zoomOutRatio) then redraw end if else redraw beep end if end if End EventHandler
EventHandler Sub Open() me.MouseCursor=System.Cursors.HandOpen // fix some properties if set wrong in IDE me.DoubleBuffer = false me.EraseBackground = false #if RBVersion >= 2013.0 then me.Transparent = False #endif End EventHandler
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) draw g End EventHandler
End Control
Control ToolMove Inherits RadioButton
ControlInstance ToolMove Inherits RadioButton
EventHandler Sub Action() out.MouseCursor=System.Cursors.HandOpen End EventHandler
End Control
Control ToolZoomIn Inherits RadioButton
ControlInstance ToolZoomIn Inherits RadioButton
EventHandler Sub Action() out.MouseCursor=System.Cursors.MagnifyLarger End EventHandler
End Control
Control ToolZoomOut Inherits RadioButton
ControlInstance ToolZoomOut Inherits RadioButton
EventHandler Sub Action() out.MouseCursor=System.Cursors.MagnifySmaller End EventHandler
End Control
EventHandler Sub Open() viewport=new CDViewPortManagerMBS viewport.setViewPortHeight 0.6 viewport.setViewPortTop 0.2 viewport.setViewPortWidth 0.1 viewport.setViewPortLeft 0.9 'viewport.setZoomInWidthLimit 0.01 'viewport.setZoomInHeightLimit 0.01 viewport.setZoomOutWidthLimit 0.2 'viewport.setZoomOutHeightLimit 1.0 dim x0 as Double=70 dim x1 as Double=50 dim x2 as Double=30 dim d as new date d.Year=d.Year-1 data0.Append x0 data1.Append x1 data2.Append x2 datax.append CDBaseChartMBS.chartTime(d.Year, d.Month, d.day) for i as integer=1 to 100 x0=x0+rnd*5.0-2.5 x1=x1+rnd*5.0-2.5 x2=x2+rnd*5.0-2.5 data0.Append x0 data1.Append x1 data2.Append x2 d.day=d.day+1 datax.append CDBaseChartMBS.chartTime(d.Year, d.Month, d.day) next // for the selection box rectanglePicture=New Picture(32,32,32) rectanglePicture.Graphics.ForeColor=&cFF0000 rectanglePicture.Graphics.FillRect 0,0,32,32 rectanglePicture.mask.Graphics.ForeColor=&cCCCCCC rectanglePicture.mask.Graphics.FillRect 0,0,32,32 End EventHandler
Protected Sub draw(g as graphics) // The data for the line chart 'dim i as integer viewport.validateViewPort // Create a XYChart object of size 600 x 375 pixels dim c as new CDXYChartMBS(600, 375) // Add a title to the chart using 18 pts Times Bold Italic font call c.addTitle("Product Line Global Revenue", "timesbi.ttf", 18) // Set the plotarea at (50, 55) and of 500 x 280 pixels in size. Use a vertical // gradient color from light blue (f9f9ff) to sky blue (aaccff) as background. // Set border to transparent and grid lines to white (ffffff). call c.setPlotArea(50, 55, 500, 280, c.linearGradientColor(0, 55, 0, 335, &hf9fcff, &haaccff), -1, c.kTransparent, &hffffff) call c.setClipping // Add a legend box at (50, 28) using horizontal layout. Use 10pts Arial Bold as // font, with transparent background. c.addLegend(50, 28, false, "arialbd.ttf", 10).setBackground(c.kTransparent) // Set the x axis labels 'call c.xAxis.setLabels(labels) // Set y-axis tick density to 30 pixels. ChartDirector auto-scaling will use this // as the guideline when putting ticks on the y-axis. c.yAxis.setTickDensity(30) c.yAxis2.setTickDensity(30) // Set axis label style to 8pts Arial Bold call c.xAxis.setLabelStyle("arialbd.ttf", 8) call c.yAxis.setLabelStyle("arialbd.ttf", 8) call c.yAxis2.setLabelStyle("arialbd.ttf", 8) // Set axis line width to 2 pixels c.xAxis.setWidth(2) c.yAxis.setWidth(2) c.yAxis2.setWidth(2) // Add axis title using 10pts Arial Bold Italic font call c.yAxis.setTitle("Revenue in US millions", "arialbi.ttf", 10) call c.yAxis2.setTitle("Revenue in US millions", "arialbi.ttf", 10) // scroll dim axisLowerLimit as double dim axisUpperLimit as double dim firstDate as Double=datax(0) dim endDate as Double=datax(UBound(datax)) dim deltaDate as Double = endDate-firstDate axisLowerLimit = endDate-deltaDate *(viewport.getViewPortLeft + viewport.getViewPortWidth) axisUpperLimit = endDate-deltaDate * viewport.getViewPortLeft c.xAxis.setDateScale(axisLowerLimit,axisUpperLimit) axisLowerLimit = 100.0-100.0 *(viewport.getViewPortTop + viewport.getViewPortHeight) axisUpperLimit = 100.0-100.0 * viewport.getViewPortTop c.yAxis.setLinearScale(axisLowerLimit,axisUpperLimit) c.yAxis.setRounding(false, false) c.yAxis2.setLinearScale(axisLowerLimit,axisUpperLimit) c.yAxis2.setRounding(false, false) // Add a line layer to the chart dim layer as CDLineLayerMBS layer = c.addLineLayer layer.setXData(datax) // Set the line width to 3 pixels layer.setLineWidth(3) // Add the three data sets to the line layer, using circles, diamands and X // shapes as symbols dim dataset as CDDataSetMBS dataset=layer.addDataSet(data0, &hff0000, "Quantum Computer") dataset.setDataSymbol(c.kCircleSymbol, 9) dataset=layer.addDataSet(data1, &h00ff00, "Atom Synthesizer") dataset.setDataSymbol(c.kDiamondSymbol, 11) dataset=layer.addDataSet(data2, &hff6600, "Proton Cannon") dataset.setDataSymbol(c.Cross2Shape, 11) lastpicture=c.makeChartPicture g.DrawPicture lastpicture,0,0 viewport.setChartMetrics c.getChartMetrics End Sub
Protected Sub redraw() Refresh End Sub
Property Protected StartX As Integer
Property Protected StartX2 As Integer
Property Protected StartY As Integer
Property Protected StartY2 As Integer
Property Protected data0() As double
Property Protected data1() As double
Property Protected data2() As double
Property Protected datax() As Double
Property Protected lastpicture As picture
Property Protected maxvalue As double
Property Protected minvalue As double
Property Protected rectanglePicture As picture
Property Protected viewport As cdviewPortManagerMBS
End Class
End Project

See also:

Feedback, Comments & Corrections

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

The biggest plugin in space...

MBS Xojo Chart Plugins