// Set the x-axis label format
c.xAxis().setLabelFormat("{value|hh:nn:ss}");
// Create a line layer to plot the lines
LineLayer layer = c.addLineLayer2();
// The x-coordinates are the timeStamps.
layer.setXData(timeStamps);
// The 3 data series are used to draw 3 lines. Here we put the latest data
// values as part of the data set name, so you can see them updated in the
// legend box.
layer.addDataSet(dataSeriesA, 0xff0000, "Software: <*bgColor=FFCCCC*>"
+ c.formatValue(dataSeriesA[dataSeriesA.length - 1], " {value|2} "));
layer.addDataSet(dataSeriesB, 0x00cc00, "Hardware: <*bgColor=CCFFCC*>"
+ c.formatValue(dataSeriesB[dataSeriesB.length - 1], " {value|2} "));
layer.addDataSet(dataSeriesC, 0x0000ff, "Services: <*bgColor=CCCCFF*>"
+ c.formatValue(dataSeriesC[dataSeriesC.length - 1], " {value|2} "));
//
// To show the capabilities of ChartDirector, we are add a movable threshold
// line to the chart and dynamically print a warning message on the chart if
// a data value exceeds the threshold
//
// Add a red mark line to the chart, with the mark label shown at the left of
// the mark line.
double thresholdValue = Double.parseDouble(alarmThreshold.getText());
Mark m = c.yAxis().addMark(thresholdValue, 0xff0000, "Alarm = " + thresholdValue);
m.setAlignment(Chart.Left);
m.setBackground(0xffcccc);
if ((dataSeriesC[dataSeriesC.length - 1] > thresholdValue)
|| (dataSeriesB[dataSeriesB.length - 1] > thresholdValue)) {
// Add an alarm message as a custom text box on top-right corner of the
// plot area if the latest data value exceeds threshold.
c.addText(575, 62, "Alarm - Latest Value Exceeded Threshold",
"Arial Bold Italic", 10, 0xffffff, Chart.TopRight).setBackground(0xdd0000);
}
// Fill the region above the threshold as semi-transparent red (80ff8888)
c.addInterLineLayer(layer.getLine(1), m.getLine(), 0x80ff8888, Chart.Transparent);
c.addInterLineLayer(layer.getLine(2), m.getLine(), 0x80ff8888, Chart.Transparent);
}
// Set the chart image to the ChartViewer
chartViewer1.setChart(c);
}