Created
October 5, 2015 08:54
-
-
Save brianhsu/fa8e41d2d006156693f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.eclipse.swt.widgets._ | |
import org.eclipse.swt.layout._ | |
import org.eclipse.swt.SWT | |
import java.awt.Color | |
import org.jfree.chart.ChartFactory | |
import org.jfree.chart.plot.XYPlot | |
import org.jfree.data.time.Minute | |
import org.jfree.data.time.TimeSeries | |
import org.jfree.data.time.TimeSeriesCollection | |
import org.jfree.data.xy.XYDataset | |
import org.jfree.ui.RectangleInsets | |
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer | |
import org.jfree.chart.axis.DateAxis | |
import java.text.SimpleDateFormat | |
import org.jfree.experimental.chart.swt.ChartComposite | |
object HelloWorld { | |
var count1 = 1 | |
var count2 = 1 | |
var count3 = 1 | |
val line1 = new TimeSeries("Status A") | |
val line2 = new TimeSeries("Status B") | |
val line3 = new TimeSeries("Status C") | |
def createChart(dataset: XYDataset) = { | |
val chart = ChartFactory.createTimeSeriesChart( | |
"中文標題測試", // title | |
"時間", // x-axis label | |
"數值", // y-axis label | |
dataset, // data | |
true, // create legend? | |
true, // generate tooltips? | |
false // generate URLs? | |
) | |
chart | |
} | |
def main(args: Array[String]) { | |
val display = new Display | |
val shell = new Shell(display) | |
val layout = new GridLayout | |
layout.numColumns = 3 | |
shell.setLayout(layout) | |
val button1 = new Button(shell, SWT.PUSH) | |
val button2 = new Button(shell, SWT.PUSH) | |
val button3 = new Button(shell, SWT.PUSH) | |
button1.setText("Add Data to Line 1") | |
button2.setText("Add Data to Line 2") | |
button3.setText("Add Data to Line 3") | |
import org.eclipse.swt.events.SelectionAdapter | |
import org.eclipse.swt.events._ | |
val dataset = new TimeSeriesCollection | |
val chart = createChart(dataset) | |
dataset.addSeries(line1) | |
dataset.addSeries(line2) | |
dataset.addSeries(line3) | |
val frame = new ChartComposite(shell, SWT.NONE, chart, true) | |
val gridData = new GridData(); | |
gridData.horizontalSpan = 3 | |
gridData.horizontalAlignment = GridData.FILL | |
gridData.grabExcessHorizontalSpace = true; | |
gridData.verticalAlignment = GridData.FILL; | |
gridData.grabExcessVerticalSpace = true; | |
frame.setLayoutData(gridData) | |
frame.setDisplayToolTips(true); | |
frame.setHorizontalAxisTrace(false); | |
frame.setVerticalAxisTrace(false); | |
button1.addSelectionListener(new SelectionAdapter() { | |
override def widgetSelected(e: SelectionEvent): Unit = { | |
line1.add(new Minute(count1, 18, 5, 10, 2015), (Math.random * 10).toInt) | |
count1 += 1 | |
} | |
}) | |
button2.addSelectionListener(new SelectionAdapter() { | |
override def widgetSelected(e: SelectionEvent): Unit = { | |
line2.add(new Minute(count2, 18, 5, 10, 2015), (Math.random * 10).toInt) | |
count2 += 1 | |
} | |
}) | |
button3.addSelectionListener(new SelectionAdapter() { | |
override def widgetSelected(e: SelectionEvent): Unit = { | |
line3.add(new Minute(count3, 18, 5, 10, 2015), (Math.random * 10).toInt) | |
count3 += 1 | |
} | |
}) | |
shell.open() | |
while (!shell.isDisposed()) { | |
if (!display.readAndDispatch()) { | |
display.sleep() | |
} | |
} | |
display.dispose() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment