We did not add direct support for setting unique colors for individual line segments in a scrolling plot because it will slow the drawing of the traces by factor of 10. Anything that breaks up long polyline runs of a single color will slow line drawing drastically. Java graphics is already slow enough.
If you can live with the speed degradation, you can probably use the segment colors of the SimpleLinePlot object attached to the RTSimpleSingleValuePlot. You must set the size of the segment buffer to the maximum number of data points that you collect, so that the buffer is large enough to hold a unique color for every data point you plan to collect. The lineplot1.initSegmentAttributes(attrib1, 1000) call in the example below sets a buffer size of 1000 and sets the default color for each line segment to the colors assigned to attrib1.
You MUST also turn off the FASTCLIP_X flag.
The following codes is a modified version of our ScrollApplication1 example program.
// declaration moved outside of the InitializeScrollGraph method so that it can be accessed from the timer1_Tick method
SimpleLinePlot lineplot1;
private void InitializeScrollGraph()
{
.
.
.
ChartAttribute attrib1 = new ChartAttribute (Color.yellow, 3, ChartConstants.LS_SOLID);
lineplot1 = new SimpleLinePlot(pTransform1, null, attrib1);
// NO FASTCLIP_X
// lineplot1.setFastClipMode( ChartConstants.FASTCLIP_X);
RTSimpleSingleValuePlot solarPanelLinePlot1 = new RTSimpleSingleValuePlot(pTransform1,lineplot1, currentTemperature1);
chartVu.addChartObject(solarPanelLinePlot1);
ChartAttribute attrib2 = new ChartAttribute (Color.green, 3,ChartConstants.LS_SOLID);
SimpleLinePlot lineplot2 = new SimpleLinePlot(pTransform1, null, attrib2);
lineplot2.setFastClipMode( ChartConstants.FASTCLIP_X);
RTSimpleSingleValuePlot solarPanelLinePlot2 = new RTSimpleSingleValuePlot(pTransform1,lineplot2, currentTemperature2);
chartVu.addChartObject(solarPanelLinePlot2);
// This must be called after the RTSimpleSingleValuePlot call
lineplot1.initSegmentAttributes(attrib1, 1000);
.
.
}
private void timer1_Tick(ActionEvent e)
{
.
.
.
counter++;
// Highlight data elements 50 to 89
if (counter == 100)
{
for (int i=0; i < 40; i++)
{
lineplot1.setSegmentColor(50 + i, ChartColors.LIGHTBLUE);
}
}
// Highlight data elements 150 to 189
if (counter == 200)
{
for (int i=0; i < 40; i++)
{
lineplot1.setSegmentColor(150 + i, ChartColors.LIGHTBLUE);
}
}
}