#Region Project Attributes
#MainFormWidth: 990
#MainFormHeight: 500
#End Region
#AdditionalJar: JHSxChart
'#VirtualMachineArgs: -Dprism.order=sw
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
Dim donutPane, piePane As JavaObject 'this is and instance of the pie/donut chart object that will be added to the RootPane of the Mainform
Dim donutchart, piechart As xPieChart 'this creates an instance of class xdonutchart - it also handles a donut chart
Dim t As Timer
Dim obj1 As Reflector
End Sub
Sub AppStart (Form1 As Form, Args() As String)
t.Initialize("t", 2000) 'just for demo purposes
MainForm = Form1
MainForm.RootPane.LoadLayout("main")
MainForm.Show
'initialize the pie chart
donutchart.initializePieChart("donut",480, 480, "The Fruit & Veg Shop") 'set the width, eight, title of the pie/donut chart
piechart.initializePieChart("pie",480, 480, "The Fruit & Veg Shop") 'set the width, eight, title of the pie/pie chart
'draw the donut chart
drawDonutChart
'draw the pie chart
drawPieChart
'NOTE - THE ABOVE TWO CALLS ONLY DIFFER IN CODE BY this single line of code:
'donutchart.PieSeriesRenderStyle = donutchart.PieSeriesRenderStyle_Donut
'for pie chart it becomes:
'piechart.PieSeriesRenderStyle = piechart.PieSeriesRenderStyle_Pie
MainForm.RootPane.AddNode(donutPane, 10, 10, 480, 480)
MainForm.RootPane.AddNode(piePane, 500, 10, 480, 480)
'The below 3 lines of code is for my laptop with Windows 10 else the graph will not display - seems to be working without these lines of code on later versions of Windows....?
Sleep(300)
MainForm.WindowLeft = MainForm.WindowLeft - 1
MainForm.WindowLeft = MainForm.WindowLeft + 1
t.Enabled = True
End Sub
'change the value(s) of the series every xxx milliseconds amd repaint the chart to see the updated chart
Sub t_tick
Dim plotBackGroundColorObject As JavaObject 'using JavaObject to pass an instance of java.awt.Color
plotBackGroundColorObject.InitializeNewInstance("java.awt.Color", Array(Rnd(0,256).As(Int), Rnd(0,256).As(Int), Rnd(0,256).As(Int)))
donutchart.PlotBackgroundColor = plotBackGroundColorObject
donutchart.updatePieSeries("Apples", Rnd(30, 300))
donutchart.updatePieSeries("Pears", Rnd(30, 300))
donutchart.updatePieSeries("Oranges", Rnd(30, 300))
donutchart.updatePieSeries("Banana", Rnd(30, 300))
Dim thickValInt As Int = Rnd(10, 81)
Dim thickValDouble As Double = thickValInt/100
donutchart.DonutTickness = thickValDouble
donutchart.repaintChart
Dim plotBackGroundColorObject As JavaObject 'using JavaObject to pass an instance of java.awt.Color
plotBackGroundColorObject.InitializeNewInstance("java.awt.Color", Array(Rnd(0,256).As(Int), Rnd(0,256).As(Int), Rnd(0,256).As(Int)))
piechart.PlotBackgroundColor = plotBackGroundColorObject
piechart.updatePieSeries("Apples", Rnd(30, 300))
piechart.updatePieSeries("Pears", Rnd(30, 300))
piechart.updatePieSeries("Oranges", Rnd(30, 300))
piechart.updatePieSeries("Banana", Rnd(30, 300))
Dim thickValInt As Int = Rnd(10, 81)
Dim thickValDouble As Double = thickValInt/100
piechart.donutTickness = thickValDouble
piechart.repaintChart
End Sub
'**************************************************************************************************************************************************
Public Sub drawDonutChart
' donutchart.initializePieChart(480, 480, "The Fruit & Veg Shop") 'set the width, eight, title of the pie/donut chart
donutPane = donutchart.drawPieChart 'basically draw a blank chart
donutchart.addSeries("Apples", 100) 'set 1st series
donutchart.addSeries("Pears", 75) 'set 2nd series
donutchart.addSeries("Oranges", 50) 'set 3rd series
donutchart.addSeries("Banana", 30) 'set 4th series
donutchart.GraphCircular = True 'make the chart circular or oval
'set the colors of the pie/donut slices
Dim slice1ColorObject, slice2ColorObject, slice3ColorObject, slice4ColorObject As JavaObject 'using JavaObject to pass an instance of java.awt.Color for the pie slice colors
slice1ColorObject.InitializeNewInstance("java.awt.Color", Array(255, 0, 0)) 'color of slice/series 1
slice2ColorObject.InitializeNewInstance("java.awt.Color", Array(0, 255, 0)) 'color of slice/series 2
slice3ColorObject.InitializeNewInstance("java.awt.Color", Array(0, 0, 255)) 'color of slice/series 3
slice4ColorObject.InitializeNewInstance("java.awt.Color", Array(255, 0, 255)) 'color of slice/series 4
'add the slice colors to the chart
Dim sliceColorArray As JavaObject
sliceColorArray.InitializeArray("java.awt.Color", Array(slice1ColorObject, slice2ColorObject, slice3ColorObject, slice4ColorObject))
donutchart.SliceColors = sliceColorArray
donutchart.StartAngle = 0 'start angle of from where to draw
donutchart.ToolTipsEnabled = True 'must tooltips be enabled?
donutchart.SliceBorderWidth = 5 'set the gap between slices
donutchart.LegendPosition = donutchart.LPosition_OutsideS 'see the other options in the pop-up
donutchart.LegendLayout = donutchart.LLayout_Horizontal 'Horizontal or Vertical
donutchart.LegendVisible = True 'must the legend be visible?
donutchart.SumVisible = True 'must the sum of the slices be visible?
donutchart.PlotContentSize = 0.4 'how much of the plot area must be used for the chart
'set the chart background color
Dim plotBackGroundColorObject As JavaObject 'using JavaObject to pass an instance of java.awt.Color
plotBackGroundColorObject.InitializeNewInstance("java.awt.Color", Array(Rnd(0,256).As(Int), Rnd(0,256).As(Int), Rnd(0,256).As(Int)))
donutchart.PlotBackgroundColor = plotBackGroundColorObject
'set the border colors
Dim plotBorderColorObject As JavaObject 'using JavaObject to pass an instance of java.awt.Color
plotBorderColorObject.InitializeNewInstance("java.awt.Color", Array(0,0,0))
donutchart.PlotBorderColor = plotBorderColorObject
'set what to display insicde the slices
donutchart.LabelType = donutchart.labelType_NameAndValue
donutchart.LabelsVisible = True
donutchart.PieSeriesRenderStyle = donutchart.PieSeriesRenderStyle_Donut 'make a donut chart. Change PieSeriesRenderStyle_Donut to PieSeriesRenderStyle_Pie to draw a Pie chart
donutchart.DonutTickness = 0.33
'set the tect color of the labels
Dim labelsFontColorObject As JavaObject
labelsFontColorObject.InitializeNewInstance("java.awt.Color", Array(0, 0, 0)) 'set the text color of the labels to black
donutchart.LabelsFontColor = labelsFontColorObject
'position the labels - see the intellisense help when hovering the mouse on donutchart.LabelsDistance
donutchart.LabelsDistance = 1.7
'set the font of the pie slice labels using JavaObject -> java.awt.Font
Dim fontType As JavaObject
fontType.InitializeStatic("java.awt.Font")
Dim labelFont As JavaObject
labelFont.InitializeNewInstance("java.awt.Font", Array(fontType.GetField("DIALOG"), fontType.GetField("HANGING_BASELINE"), 12)) 'MONOSPACED, SANS_SERIF, SERIF, DIALOG, DIALOG_INPUT
'BOLD, PLAIN, CENTER_BASELINE, HANGING_BASELINE, ITALIC, TRUETYPE_FONT, TYPE1_FONT, ROMAN_BASELINE
donutchart.LabelsFont = labelFont
'set the font of the chart title using JavaObject -> java.awt.Font
Dim fontType As JavaObject
fontType.InitializeStatic("java.awt.Font")
Dim titleFont As JavaObject
titleFont.InitializeNewInstance("java.awt.Font", Array(fontType.GetField("SANS_SERIF"), fontType.GetField("BOLD"), 18)) 'MONOSPACED, SANS_SERIF, SERIF, DIALOG, DIALOG_INPUT
'BOLD, PLAIN, CENTER_BASELINE, HANGING_BASELINE, ITALIC, TRUETYPE_FONT, TYPE1_FONT, ROMAN_BASELINE
donutchart.ChartTitleFont = titleFont
'set the text color of the chart title, axes labes, and legend
Dim chartFontColorObject As JavaObject
chartFontColorObject.InitializeNewInstance("java.awt.Color", Array(25, 50, 200))
donutchart.ChartFontColor = chartFontColorObject
'set the background color of the legend
Dim legendBackgroundColorObject As JavaObject
legendBackgroundColorObject.InitializeNewInstance("java.awt.Color", Array(200, 200, 0))
donutchart.LegendBackgroundColor = legendBackgroundColorObject
'set the border color of the legend
Dim legendBorderColorObject As JavaObject
legendBorderColorObject.InitializeNewInstance("java.awt.Color", Array(0, 0, 0))
donutchart.LegendBorderColor = legendBorderColorObject
'set the font of the legend using JavaObject -> java.awt.Font
Dim fontType As JavaObject
fontType.InitializeStatic("java.awt.Font")
Dim legendFont As JavaObject
legendFont.InitializeNewInstance("java.awt.Font", Array(fontType.GetField("SANS_SERIF"), fontType.GetField("ITALIC"), 15)) 'MONOSPACED, SANS_SERIF, SERIF, DIALOG, DIALOG_INPUT
'BOLD, PLAIN, CENTER_BASELINE, HANGING_BASELINE, ITALIC, TRUETYPE_FONT, TYPE1_FONT, ROMAN_BASELINE
donutchart.LegendFont = legendFont
'set the background color of the title box
Dim titleBackgroundColorObject As JavaObject
titleBackgroundColorObject.InitializeNewInstance("java.awt.Color", Array(255, 0, 0))
donutchart.ChartTitleBoxBackgroundColor = titleBackgroundColorObject
'set the border color of the title box
Dim titleBoxBorderColorObject As JavaObject
titleBoxBorderColorObject.InitializeNewInstance("java.awt.Color", Array(0, 0, 0))
donutchart.ChartTitleBoxBorderColor = titleBoxBorderColorObject
donutchart.ChartTitleBoxVisible = True
Dim tooltipBorderColorObject As JavaObject
tooltipBorderColorObject.InitializeNewInstance("java.awt.Color", Array(255, 0, 0))
donutchart.ToolTipBorderColor = tooltipBorderColorObject
Dim tooltipBackgroundColorObject As JavaObject
tooltipBackgroundColorObject.InitializeNewInstance("java.awt.Color", Array(255, 200, 200))
donutchart.ToolTipBackgroundColor = tooltipBackgroundColorObject
'set the font of the tooltip
Dim fontType As JavaObject
fontType.InitializeStatic("java.awt.Font")
Dim tooltipFontObject As JavaObject
tooltipFontObject.InitializeNewInstance("java.awt.Font", Array(fontType.GetField("SANS_SERIF"), fontType.GetField("ITALIC"), 15)) 'MONOSPACED, SANS_SERIF, SERIF, DIALOG, DIALOG_INPUT
'BOLD, PLAIN, CENTER_BASELINE, HANGING_BASELINE, ITALIC, TRUETYPE_FONT, TYPE1_FONT, ROMAN_BASELINE
donutchart.ToolTipFont = tooltipFontObject
End Sub
'********************************************************************************************************************************************
Public Sub drawPieChart
' piechart.initializePieChart(480, 480, "The Fruit & Veg Shop") 'set the width, eight, title of the pie/pie chart
piePane = piechart.drawPieChart 'basically draw a blank chart
piechart.addSeries("Apples", 100) 'set 1st series
piechart.addSeries("Pears", 75) 'set 2nd series
piechart.addSeries("Oranges", 50) 'set 3rd series
piechart.addSeries("Banana", 30) 'set 4th series
piechart.GraphCircular = True 'make the chart circular or oval
'set the colors of the pie/pie slices
Dim slice1ColorObject, slice2ColorObject, slice3ColorObject, slice4ColorObject As JavaObject 'using JavaObject to pass an instance of java.awt.Color for the pie slice colors
slice1ColorObject.InitializeNewInstance("java.awt.Color", Array(255, 0, 0)) 'color of slice/series 1
slice2ColorObject.InitializeNewInstance("java.awt.Color", Array(0, 255, 0)) 'color of slice/series 2
slice3ColorObject.InitializeNewInstance("java.awt.Color", Array(0, 0, 255)) 'color of slice/series 3
slice4ColorObject.InitializeNewInstance("java.awt.Color", Array(255, 0, 255)) 'color of slice/series 4
'add the slice colors to the chart
Dim sliceColorArray As JavaObject
sliceColorArray.InitializeArray("java.awt.Color", Array(slice1ColorObject, slice2ColorObject, slice3ColorObject, slice4ColorObject))
piechart.SliceColors = sliceColorArray
piechart.StartAngle = 0 'start angle of from where to draw
piechart.ToolTipsEnabled = True 'must tooltips be enabled?
piechart.SliceBorderWidth = 5 'set the gap between slices
piechart.LegendPosition = piechart.LPosition_OutsideS 'see the other options in the pop-up
piechart.LegendLayout = piechart.LLayout_Horizontal 'Horizontal or Vertical
piechart.LegendVisible = True 'must the legend be visible?
piechart.SumVisible = True 'must the sum of the slices be visible?
piechart.PlotContentSize = 0.4 'how much of the plot area must be used for the chart
'set the chart background color
Dim plotBackGroundColorObject As JavaObject 'using JavaObject to pass an instance of java.awt.Color
plotBackGroundColorObject.InitializeNewInstance("java.awt.Color", Array(Rnd(0,256).As(Int), Rnd(0,256).As(Int), Rnd(0,256).As(Int)))
piechart.PlotBackgroundColor = plotBackGroundColorObject
'set the border colors
Dim plotBorderColorObject As JavaObject 'using JavaObject to pass an instance of java.awt.Color
plotBorderColorObject.InitializeNewInstance("java.awt.Color", Array(0,0,0))
piechart.PlotBorderColor = plotBorderColorObject
'set what to display insicde the slices
piechart.LabelType = piechart.labelType_NameAndValue
piechart.LabelsVisible = True
piechart.PieSeriesRenderStyle = piechart.PieSeriesRenderStyle_Pie 'make a pie chart. Change PieSeriesRenderStyle_pie to PieSeriesRenderStyle_Pie to draw a Pie chart
piechart.donutTickness = 0.33
'set the tect color of the labels
Dim labelsFontColorObject As JavaObject
labelsFontColorObject.InitializeNewInstance("java.awt.Color", Array(0, 0, 0)) 'set the text color of the labels to black
piechart.LabelsFontColor = labelsFontColorObject
'position the labels - see the intellisense help when hovering the mouse on piechart.LabelsDistance
piechart.LabelsDistance = 1.7
'set the font of the pie slice labels using JavaObject -> java.awt.Font
Dim fontType As JavaObject
fontType.InitializeStatic("java.awt.Font")
Dim labelFont As JavaObject
labelFont.InitializeNewInstance("java.awt.Font", Array(fontType.GetField("DIALOG"), fontType.GetField("HANGING_BASELINE"), 12)) 'MONOSPACED, SANS_SERIF, SERIF, DIALOG, DIALOG_INPUT
'BOLD, PLAIN, CENTER_BASELINE, HANGING_BASELINE, ITALIC, TRUETYPE_FONT, TYPE1_FONT, ROMAN_BASELINE
piechart.LabelsFont = labelFont
'set the font of the chart title using JavaObject -> java.awt.Font
Dim fontType As JavaObject
fontType.InitializeStatic("java.awt.Font")
Dim titleFont As JavaObject
titleFont.InitializeNewInstance("java.awt.Font", Array(fontType.GetField("DIALOG"), fontType.GetField("ITALIC"), 18)) 'MONOSPACED, SANS_SERIF, SERIF, DIALOG, DIALOG_INPUT
'BOLD, PLAIN, CENTER_BASELINE, HANGING_BASELINE, ITALIC, TRUETYPE_FONT, TYPE1_FONT, ROMAN_BASELINE
piechart.ChartTitleFont = titleFont
'set the text color of the chart title, axes labes, and legend
Dim chartFontColorObject As JavaObject
chartFontColorObject.InitializeNewInstance("java.awt.Color", Array(25, 50, 200))
piechart.ChartFontColor = chartFontColorObject
'set the background color of the legend
Dim legendBackgroundColorObject As JavaObject
legendBackgroundColorObject.InitializeNewInstance("java.awt.Color", Array(200, 200, 0))
piechart.LegendBackgroundColor = legendBackgroundColorObject
'set the border color of the legend
Dim legendBorderColorObject As JavaObject
legendBorderColorObject.InitializeNewInstance("java.awt.Color", Array(0, 0, 0))
piechart.LegendBorderColor = legendBorderColorObject
'set the font of the legend using JavaObject -> java.awt.Font
Dim fontType As JavaObject
fontType.InitializeStatic("java.awt.Font")
Dim legendFont As JavaObject
legendFont.InitializeNewInstance("java.awt.Font", Array(fontType.GetField("SANS_SERIF"), fontType.GetField("ITALIC"), 15)) 'MONOSPACED, SANS_SERIF, SERIF, DIALOG, DIALOG_INPUT
'BOLD, PLAIN, CENTER_BASELINE, HANGING_BASELINE, ITALIC, TRUETYPE_FONT, TYPE1_FONT, ROMAN_BASELINE
piechart.LegendFont = legendFont
'set the background color of the title box
Dim titleBackgroundColorObject As JavaObject
titleBackgroundColorObject.InitializeNewInstance("java.awt.Color", Array(255, 0, 0))
piechart.ChartTitleBoxBackgroundColor = titleBackgroundColorObject
'set the border color of the title box
Dim titleBoxBorderColorObject As JavaObject
titleBoxBorderColorObject.InitializeNewInstance("java.awt.Color", Array(0, 0, 0))
piechart.ChartTitleBoxBorderColor = titleBoxBorderColorObject
piechart.ChartTitleBoxVisible = False
Dim tooltipBorderColorObject As JavaObject
tooltipBorderColorObject.InitializeNewInstance("java.awt.Color", Array(255, 0, 0))
piechart.ToolTipBorderColor = tooltipBorderColorObject
Dim tooltipBackgroundColorObject As JavaObject
tooltipBackgroundColorObject.InitializeNewInstance("java.awt.Color", Array(255, 200, 200))
piechart.ToolTipBackgroundColor = tooltipBackgroundColorObject
'set the font of the tooltip
Dim fontType As JavaObject
fontType.InitializeStatic("java.awt.Font")
Dim tooltipFontObject As JavaObject
tooltipFontObject.InitializeNewInstance("java.awt.Font", Array(fontType.GetField("SANS_SERIF"), fontType.GetField("ITALIC"), 15)) 'MONOSPACED, SANS_SERIF, SERIF, DIALOG, DIALOG_INPUT
'BOLD, PLAIN, CENTER_BASELINE, HANGING_BASELINE, ITALIC, TRUETYPE_FONT, TYPE1_FONT, ROMAN_BASELINE
piechart.ToolTipFont = tooltipFontObject
End Sub
public Sub pie_chartvalue_clicked (tooltip As Object) 'This is an Event and is raised from class "piechart" - the data comes in as a List (passed to here as an object)
Dim answer As String = tooltip
Dim starting As Int = answer.IndexOf("'")
Dim ending As Int = answer.IndexOf2("'", starting + 1)
answer = answer.SubString2(starting+1, ending)
Dim series() As String = Regex.Split(" ", answer)
Dim name As String = series(0)
Dim val As String = series(1)
val = val.Replace("(", "")
val = val.Replace(")", "")
val = val.Replace(",", ".")
Dim valDouble As Double = val
Log("PIE Series Name = " & name)
Log("PIE Series Value = " & valDouble)
End Sub
public Sub donut_chartvalue_clicked (tooltip As Object) 'This is an Event and is raised from class "piechart" - the data comes in as a List (passed to here as an object)
Dim answer As String = tooltip
Dim starting As Int = answer.IndexOf("'")
Dim ending As Int = answer.IndexOf2("'", starting + 1)
answer = answer.SubString2(starting+1, ending)
Dim series() As String = Regex.Split(" ", answer)
Dim name As String = series(0)
Dim val As String = series(1)
val = val.Replace("(", "")
val = val.Replace(")", "")
val = val.Replace(",", ".")
Dim valDouble As Double = val
Log("DONUT Series Name = " & name)
Log("DONUT Series Value = " & valDouble)
End Sub
public Sub pie_mouse_pressed (pressed As String)
Log("MOUSE PRESSED ON PIE CHART")
End Sub
public Sub donut_mouse_pressed (pressed As String)
Log("MOUSE PRESSED ON DONUT CHART")
End Sub
public Sub pie_mouse_released (pressed As String)
Log("MOUSE RELEASED ON PIE CHART")
End Sub
public Sub donut_mouse_released (pressed As String)
Log("MOUSE RELEASED ON DONUT CHART")
End Sub
public Sub pie_mouse_exited (pressed As String)
Log("MOUSE EXITED ON PIE CHART")
End Sub
public Sub donut_mouse_exited (pressed As String)
Log("MOUSE EXITED ON DONUT CHART")
End Sub
public Sub pie_mouse_entered (pressed As String)
Log("MOUSE ENTERED ON PIE CHART")
End Sub
public Sub donut_mouse_entered (pressed As String)
Log("MOUSE ENTERED ON DONUT CHART")
End Sub