Adding legend to jFreechart

一世执手 提交于 2019-12-04 02:09:25

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/14979659/adding-legend-to-jfreechart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!