向jFreechart添加图例 [英] Adding legend to jFreechart
问题描述
我得出了最终的磁滞曲线,如下所示:
我之前的帖子: 使用jFreeChart绘制磁滞回线
我在第一个磁滞回线中使用了4个XYSeries,在第二个磁滞回线中使用了另外四个.
如果我打开图例
JFreeChart chart = ChartFactory.createXYLineChart(
"Hysteresis Plot", // chart title
"Pounds(lb)", // domain axis label
"Movement(inch)", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);
它看起来像这样:
我只想显示蓝色是我的第一个磁滞回线,红色是我的第二个磁滞回线,我已将其作为副标题添加在第一张图片中作为解决方法.有人可以指导我如何添加手动图例,该图例将蓝色表示为第一个循环,将红色表示为第二个循环.
谢谢
由于ChartFactory.createXYLineChart()
创建了XYPlot
,因此您可以尝试此处和此处.
更雄心勃勃的方案是隐藏原始图例,并将图例项呈现在单独的组件中,如此处所示.
I have come up with my final hysteresis plot, which looks like this:
My earlier post: Plotting a hysteresis loop with jFreeChart
I have used 4 XYSeries for my first hysteresis loop and another four for the second hysteresis loop.
If i turn on the legend
JFreeChart chart = ChartFactory.createXYLineChart(
"Hysteresis Plot", // chart title
"Pounds(lb)", // domain axis label
"Movement(inch)", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);
it appears like this :
I just want to show that blue is my first hysteresis loop and red is my second hysteresis loop, which I have added as subtitle in the first pic as workaround. Can someone guide how I can add manual legends which indicate blue as first loop and red as second.
Thanks
Because ChartFactory.createXYLineChart()
creates an XYPlot
, you could try setFixedLegendItems()
, mentioned here and here.
A more ambitious scheme is to suppress the native legend and render the legend items in a separate component, as shown here.
这篇关于向jFreechart添加图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!