I have a simple bar chart and I draw a line using ColorLine object to set a limit. (I attached an image to illustrate my point) Is there a way to add the colorline to chart legend? I couldn't find any API to do that. If not, what is alternative way to achieve this?
Code: Select all
public static void main(String[] args) {
JFrame frame = new JFrame();
JPanel panel = new JPanel();
panel.setSize(600, 600);
TChart chart = new TChart();
panel.add(chart);
StringList labelsList = new StringList(3);
labelsList.add(0, "1.11");
labelsList.add(1, "2.22");
labelsList.add(2, "3.33");
Bar blueSeries = new Bar(chart.getChart());
blueSeries.setMultiBar(MultiBars.STACKED);
blueSeries.add(0, 10, "A");
blueSeries.add(1, 20, "B");
blueSeries.add(2, 30, "C");
blueSeries.getMarks().setVisible(true);
blueSeries.setTitle("blue series");
blueSeries.setLabels(labelsList);
blueSeries.getMarks().getFont().setSize(20); // size
blueSeries.getMarks().getFont().setColor(Color.red); // color
blueSeries.getMarks().getFont().setBold(true); //bold
blueSeries.getMarks().getFont().setItalic(true); //italic
blueSeries.getMarks().getFont().setName("");// style
ColorLine line = new ColorLine(chart.getChart());
line.getPen().setColor(Color.RED);
line.setAxis(chart.getAxes().getLeft());
line.setValue(15);
//custom x label
chart.getAxes().getBottom().getCustomLabels().clear();
chart.getAxes().getBottom().getCustomLabels().add(0.0, "A");
chart.getAxes().getBottom().getCustomLabels().add(1.0, "B");
chart.getAxes().getBottom().getCustomLabels().add(2.0, "C");
chart.getAspect().setView3D(false);
frame.add(panel);
frame.setSize(600, 600);
frame.setVisible(true);
}