更改JFreeChart的线条样式和颜色 [英] Change the Lines Style and colour of a JFreeChart

查看:319
本文介绍了更改JFreeChart的线条样式和颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个系列:

XYSeries s1 = new XYSeries("one");
s1.add(1,0);
s1.add(2,1);

XYSeries s2 = new XYSeries("two");
s1.add(3,0);
s1.add(4,1);

XYSeries s3 = new XYSeries("three");
s1.add(5,0);
s1.add(6,1);

我将其绘制为XYLineChart:

Which i plot as a XYLineChart:

XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(s1);
dataset.addSeries(s2);
dataset.addSeries(s3);

JFreeChart chart = ChartFactory.createXYLineChart("title", "x", "y", dataset, PlotOrientation.VERTICAL, false, false, false);

并添加到面板:

ChartPanel cp = new ChartPanel(chart);
panel_1.add(cp, BorderLayout.CENTER);
panel_1.validate();

我如何使s1和s2系列具有相同的颜色,而s3不同?

How do i make it so series s1 and s2 are the same colour, and s3 is different?

推荐答案

您可以使用渲染器的setSeriesPaint()方法指定seriespaint.还可以考虑使用自定义DrawingSupplier,在此处中已提及.更一般而言,您可以覆盖所需的get*Paint()方法以建立任何所需的配色方案,如 此处所示.

You can use the renderer's setSeriesPaint() method to specify the series and paint. Also consider using a custom DrawingSupplier, mentioned here. More generally, you can override the desired get*Paint() methods to establish any desired color scheme, as shown here for getItemFillPaint()

这篇关于更改JFreeChart的线条样式和颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆