XYLineAndShapeRenderer 如何将数据集与图形连接起来?

How does XYLineAndShapeRenderer connect a dataset with a graph?

这是一个例子;它像这样设置渲染:

final XYPlot plot = xylineChart.getXYPlot( );
XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer( );
renderer.setSeriesPaint( 0 , Color.RED );
renderer.setSeriesPaint( 1 , Color.GREEN );
renderer.setSeriesPaint( 2 , Color.YELLOW );
renderer.setSeriesStroke( 0 , new BasicStroke( 4.0f ) );
renderer.setSeriesStroke( 1 , new BasicStroke( 3.0f ) );
renderer.setSeriesStroke( 2 , new BasicStroke( 2.0f ) );
plot.setRenderer( renderer ); 

数据集是这样的:

final XYSeries firefox = new XYSeries( "Firefox" );
firefox.add( 1.0 , 1.0 );
firefox.add( 2.0 , 4.0 );
firefox.add( 3.0 , 3.0 );
final XYSeries chrome = new XYSeries( "Chrome" );
chrome.add( 1.0 , 4.0 );
chrome.add( 2.0 , 5.0 );
chrome.add( 3.0 , 6.0 );
final XYSeries iexplorer = new XYSeries( "InternetExplorer" );
iexplorer.add( 3.0 , 4.0 );
iexplorer.add( 4.0 , 5.0 );
iexplorer.add( 5.0 , 4.0 );
final XYSeriesCollection dataset = new XYSeriesCollection( );
dataset.addSeries( firefox );
dataset.addSeries( chrome );
dataset.addSeries( iexplorer );

那么结果是这样的:

我看不到任何代码给每个数据系列一个唯一的图表,但结果给出了图表之前设置的三种数据,例如firefox是红色的,chrome是绿色的。

图是按顺序分配的吗?

如果是这样,如果我向数据集添加另一个数据,它会分配哪种颜色?

如果没有,如何将图表与数据联系起来?如果我想给 firefox green 和 chrome red 怎么办?

非常感谢!

Is the graph assigned in order?

一个“XYPlot makes use of an XYItemRenderer to draw each point on the plot." This includes all points in all series in the plot's XYDataset. Your example's dataset includes three series, each having three points; moreover, each point in a series is connected by a line, as your image illustrates. The order within an XYSeries is sorted by default, as shown here.

If so, if I add another data to the dataset, which colour it will be assigned? If not, how to connect the graph with the data? What if I want to give firefox green and chrome red?

没有明确调用 setSeriesPaint(),下一个颜色由绘图的 DrawingSupplier 提供,已讨论 here. The choice may be influenced by your use case: for example, a custom DrawingSupplier is warranted if the chart's plot and legend should match in a particular way, as shown and