use java.awt.BasicStroke
use java.text.SimpleDateFormat
use org.jfree.data.xy.XYDataset
use org.jfree.data.xy.XYSeries
use org.jfree.chart.axis.DateTickUnit; rem ' JFreeChart 1.0.x
use org.jfree.chart.axis.DateTickUnitType; rem ' JFreeChart 1.5.x
use org.jfree.chart.JFreeChart
use org.jfree.chart.ChartFactory
use org.jfree.chart.ChartPanel
use org.jfree.chart.plot.XYPlot
use org.jfree.data.xy.XYSeriesCollection
use org.jfree.data.time.TimeSeries
use org.jfree.data.time.TimeSeriesCollection
use org.jfree.data.time.Day
use org.jfree.chart.renderer.xy.XYLineAndShapeRenderer
rem ' Migrating from JFreeChart 1.0.x to JFreeChart 1.5.x:
rem ' https://github.com/jfree/jfreechart/blob/master/README.md
rem '=====
rem 'Setup
rem '=====
sysgui = unt
open (sysgui)"X0"
web = info(3,6)="5" or info(3,6)="6"
x=50,y=50,w=1050,h=600; if web then x=0,y=0
sysgui! = bbjapi().getSysGui()
window! = sysgui!.addWindow(x,y,w,h,"BBjChart Samples",$00090083$)
window!.setCallback(window!.ON_CLOSE,"eoj")
window!.setCallback(window!.ON_MOUSE_DOWN,"event")
window!.setCallback(window!.ON_RIGHT_MOUSE_DOWN,"event")
window!.setCallback(window!.ON_MOUSE_UP,"event")
window!.setCallback(window!.ON_MOUSE_MOVE,"event")
window!.setCallback(window!.ON_MOUSE_SCROLL,"event")
window!.setCallback(window!.ON_CLICK,"event")
window!.setCallback(window!.ON_DOUBLE_CLICK,"event")
window!.setCallback(window!.ON_POPUP_REQUEST,"event")
window!.setCallback(window!.ON_MOUSE_ENTER,"event")
window!.setCallback(window!.ON_MOUSE_EXIT,"event")
window!.setCallback(window!.ON_WINDOW_GAINED_FOCUS,"event")
window!.setCallback(window!.ON_WINDOW_LOST_FOCUS,"event")
showLegend = 1
is3d = 1
rem '===========
rem 'BBjPieChart
rem '===========
pieChart! = window!.addPieChart(101,10,10,500,270,showLegend,is3d)
pieChart!.setBackColor(window!.getBackColor())
pieChart!.setToolTipText("BBjPieChart")
pieChart!.setTitle("Receipts by Geographic Area")
pieChart!.setSliceValue("Western Europe",43.2)
pieChart!.setSliceValue("Mexico",10)
pieChart!.setSliceValue("Pacific Rim",17.5)
pieChart!.setSliceValue("Eastern Europe",15.2)
pieChart!.setSliceValue("U.S",32.5)
pieChart!.setSliceValue("Other",6)
pieChart!.setCallback(sysgui!.ON_GAINED_FOCUS,"event")
pieChart!.setCallback(sysgui!.ON_LOST_FOCUS,"event")
pieChart!.setCallback(sysgui!.ON_MOUSE_ENTER,"event")
pieChart!.setCallback(sysgui!.ON_MOUSE_EXIT,"event")
pieChart!.setCallback(sysgui!.ON_POPUP_REQUEST,"event")
pieChart!.setCallback(sysgui!.ON_RIGHT_MOUSE_DOWN,"event")
flags$ = iff(showLegend,$0004$,$0000$)
pieChartLegend! = window!.addCheckBox(102,10,280,500,20,"Pie Chart Legend",flags$)
pieChartLegend!.setCallback(pieChartLegend!.ON_CHECK_ON,"pieChartLegendOn")
pieChartLegend!.setCallback(pieChartLegend!.ON_CHECK_OFF,"pieChartLegendOff")
rem '===========
rem 'BBjBarChart
rem '===========
barChart! = window!.addBarChart(103,10,300,500,270,"Fruit","Value",3,5,showLegend,is3d,0)
barChart!.setBackColor(window!.getBackColor())
barChart!.setToolTipText("BBjBarChart")
barChart!.setTitle("Travel Expense by Region")
barChart!.setSeriesName(0,"Europe")
barChart!.setSeriesName(1,"U.S.")
barChart!.setSeriesName(1,"U.S.A.")
barChart!.setSeriesName(2,"Other")
barChart!.setCategoryName(0,"2018")
barChart!.setCategoryName(1,"2019")
barChart!.setCategoryName(2,"2020")
barChart!.setCategoryName(3,"2021")
barChart!.setCategoryName(4,"2022 (est)")
barChart!.setBarValue(0,0,1)
barChart!.setBarValue(0,1,4)
barChart!.setBarValue(0,2,3)
barChart!.setBarValue(0,3,5)
barChart!.setBarValue(0,4,5)
barChart!.setBarValue(1,0,5)
barChart!.setBarValue(1,1,7)
barChart!.setBarValue(1,2,6)
barChart!.setBarValue(1,3,8)
barChart!.setBarValue(1,4,4)
barChart!.setBarValue(2,0,4)
barChart!.setBarValue(2,1,3)
barChart!.setBarValue(2,2,2)
barChart!.setBarValue(2,3,3)
barChart!.setBarValue(2,4,6)
barChart!.setCallback(sysgui!.ON_GAINED_FOCUS,"event")
barChart!.setCallback(sysgui!.ON_LOST_FOCUS,"event")
barChart!.setCallback(sysgui!.ON_MOUSE_ENTER,"event")
barChart!.setCallback(sysgui!.ON_MOUSE_EXIT,"event")
barChart!.setCallback(sysgui!.ON_POPUP_REQUEST,"event")
barChart!.setCallback(sysgui!.ON_RIGHT_MOUSE_DOWN,"event")
flags$ = iff(showLegend,$0004$,$0000$)
barChartLegend! = window!.addCheckBox(104,10,570,500,20,"Bar Chart Legend",flags$)
barChartLegend!.setCallback(barChartLegend!.ON_CHECK_ON,"barChartLegendOn")
barChartLegend!.setCallback(barChartLegend!.ON_CHECK_OFF,"barChartLegendOff")
rem '============
rem 'BBjLineChart
rem '============
if (0) then
rem 'if msgbox("Scrolling Line Chart?",4+32,"Scrollbars") = 6 then
rem ' this puts it on a scrollable child window
scrollingLineChart! = window!.addChildWindow(105,520,10,1000,270,"",$000100804$,1)
scrollingLineChart!.setTrack(0)
scrollingLineChart!.setSize(500,270)
lineChart! = scrollingLineChart!.addLineChart(105,0,0,1000,270,"x","y",2,showLegend)
else
rem ' this puts it directly on the main window
lineChart! = window!.addLineChart(105,520,10,500,270,"x","y",2,showLegend)
endif
lineChart!.setBackColor(window!.getBackColor())
lineChart!.setToolTipText("BBjLineChart")
lineChart!.setTitle("Noise levels")
lineChart!.setSeriesName(0,"High frequency")
lineChart!.setSeriesName(1,"Low frequency")
for i = 1 to 200
x = i/10 - 10
y = Math.cos(x)
z = Math.sin(x) * 2
lineChart!.setXYValue(0,x,y)
lineChart!.setXYValue(1,x,z)
next i
lineChart!.setCallback(sysgui!.ON_GAINED_FOCUS,"event")
lineChart!.setCallback(sysgui!.ON_LOST_FOCUS,"event")
lineChart!.setCallback(sysgui!.ON_MOUSE_ENTER,"event")
lineChart!.setCallback(sysgui!.ON_MOUSE_EXIT,"event")
lineChart!.setCallback(sysgui!.ON_POPUP_REQUEST,"event")
lineChart!.setCallback(sysgui!.ON_RIGHT_MOUSE_DOWN,"event")
flags$ = iff(showLegend,$0004$,$0000$)
lineChartLegend! = window!.addCheckBox(106,520,280,500,20,"Line Chart Legend",flags$)
lineChartLegend!.setCallback(lineChartLegend!.ON_CHECK_ON,"lineChartLegendOn")
lineChartLegend!.setCallback(lineChartLegend!.ON_CHECK_OFF,"lineChartLegendOff")
rem '===============
rem 'BBjGenericChart
rem '===============
rem 'if info(3,6)="5" then goto skip; rem ' BUI
rem 'if info(3,6)="6" then goto skip; rem ' DWC
seterr skip
series! = new TimeSeries@("Random Data")
current! = new org.jfree.data.time.Day@(1,1,2021)
value = 62
for i = 0 to 360
delta = i/60
value = value + Math.random() - .5
series!.add(current!,new Double(value + delta))
current! = current!.next()
next i
dataset! = new TimeSeriesCollection@(series!)
chart! = ChartFactory@.createTimeSeriesChart("2021 Values","Date","Value",dataset!,0,0,0)
color! = window!.getBackColor()
paint! = new java.awt.Color@(color!.getRed(),color!.getGreen(),color!.getBlue())
chart!.setBackgroundPaint(paint!)
list! = bbjapi().makeVector()
list!.add(new Float(10).floatValue())
list!.add(new Float(1).floatValue())
CAP_ROUND = BasicStroke.CAP_ROUND
JOIN_ROUND = BasicStroke.JOIN_ROUND
stroke! = new BasicStroke@(1,CAP_ROUND,JOIN_ROUND,5,list!,0)
renderer! = new XYLineAndShapeRenderer@()
renderer!.setBaseShapesVisible(0,err=*next); rem ' JFreeChart 1.0.x
renderer!.setDefaultShapesVisible(0,err=*next); rem ' JFreeChart 1.5.x
renderer!.setSeriesStroke(0,stroke!)
plot! = chart!.getPlot()
plot!.setRenderer(renderer!)
format! = new SimpleDateFormat@("MMM-yyyy")
tickUnit! = null()
tickUnit! = new DateTickUnit@(DateTickUnit@.MONTH,1,format!,err=*next); rem ' JFreeChart 1.0.x
if (tickUnit! = null()) then
tickUnit! = new DateTickUnit@(DateTickUnitType@.MONTH,1,format!,err=*next); rem ' JFreeChart 1.5.x
endif
axis! = plot!.getDomainAxis()
axis!.setTickUnit(tickUnit!)
axis!.setVerticalTickLabels(1)
genericChart! = window!.addGenericChart(107,520,300,500,270)
genericChart!.setToolTipText("BBjGenericChart")
genericChart!.setClientChart(chart!)
genericChart!.getClientChartPanel().setMouseZoomable(1,0)
genericChart!.setCallback(sysgui!.ON_GAINED_FOCUS,"event")
genericChart!.setCallback(sysgui!.ON_LOST_FOCUS,"event")
genericChart!.setCallback(sysgui!.ON_MOUSE_ENTER,"event")
genericChart!.setCallback(sysgui!.ON_MOUSE_EXIT,"event")
genericChart!.setCallback(sysgui!.ON_POPUP_REQUEST,"event")
genericChart!.setCallback(sysgui!.ON_RIGHT_MOUSE_DOWN,"event")
skip: seterr 0
process_events
eoj:
release
event:
event! = sysgui!.getLastEvent()
control! = event!.getControl()
print control!," ",event!
rem 'System.err.println(str(control!)+" "+str(event!))
return
pieChartLegendOn:
pieChart!.setLegendShown(1,err=*next); rem ' BBj 19.10+
print "BBjPieChart::isLegendShown ",pieChart!.isLegendShown()
return
pieChartLegendOff:
pieChart!.setLegendShown(0,err=*next); rem ' BBj 19.10+
print "BBjPieChart::isLegendShown ",pieChart!.isLegendShown()
return
barChartLegendOn:
barChart!.setLegendShown(1,err=*next); rem ' BBj 19.10+
print "BBjBarChart::isLegendShown ",barChart!.isLegendShown()
return
barChartLegendOff:
barChart!.setLegendShown(0,err=*next); rem ' BBj 19.10+
print "BBjBarChart::isLegendShown ",barChart!.isLegendShown()
return
lineChartLegendOn:
lineChart!.setLegendShown(1,err=*next); rem ' BBj 19.10+
print "BBjLineChart::isLegendShown ",lineChart!.isLegendShown()
return
lineChartLegendOff:
lineChart!.setLegendShown(0,err=*next); rem ' BBj 19.10+
print "BBjLineChart::isLegendShown ",lineChart!.isLegendShown()
return
|