Example usage for org.jfree.chart LegendItem LegendItem

List of usage examples for org.jfree.chart LegendItem LegendItem

Introduction

In this page you can find the example usage for org.jfree.chart LegendItem LegendItem.

Prototype

public LegendItem(String label) 

Source Link

Document

Creates a legend item with the specified label.

Usage

From source file:pwm.visualizer.MDPPolicyPanel.java

private JFreeChart createChart() {
    NumberAxis nutritionAxis = new NumberAxis("Calories/Day");
    nutritionAxis.setLowerBound(0);/*from   w  ww  .  j a v  a2s  . c o  m*/
    nutritionAxis.setUpperBound(5000);
    nutritionAxis.setAutoRange(false);
    //      
    CategoryPlot categoryplot = new CategoryPlot(nutritionDataSet, new CategoryAxis("Weight(KG)"),
            nutritionAxis, new BarRenderer());
    CategoryAxis xaxis = categoryplot.getDomainAxis();
    xaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);

    LegendItemCollection legend = new LegendItemCollection();
    LegendItem nutritionLegend = new LegendItem("Calories/Day");
    LegendItem exerciseLegend = new LegendItem("Physical Activity Level");
    nutritionLegend.setFillPaint(Color.BLUE);
    exerciseLegend.setFillPaint(Color.RED);

    legend.add(nutritionLegend);
    legend.add(exerciseLegend);

    categoryplot.setFixedLegendItems(legend);
    JFreeChart jfreechart = new JFreeChart("Policy Visualizer", categoryplot);
    categoryplot.setDataset(1, exerciseDataSet);
    categoryplot.mapDatasetToRangeAxis(1, 1);

    NumberAxis exerciseAxis = new NumberAxis("Physical Activity Level");
    exerciseAxis.setLowerBound(0);
    exerciseAxis.setUpperBound(3.0);
    exerciseAxis.setAutoRange(false);

    categoryplot.setRangeAxis(1, exerciseAxis);
    BarRenderer barrenderer1 = new BarRenderer();
    categoryplot.setRenderer(1, barrenderer1);

    //        BarRenderer stackedbarrenderer = (BarRenderer)categoryplot.getRenderer();
    //        stackedbarrenderer.setDrawBarOutline(true);
    //        stackedbarrenderer.setBaseItemLabelsVisible(false);
    //        stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());

    ChartUtilities.applyCurrentTheme(jfreechart);

    return jfreechart;

}

From source file:com.bdb.weather.display.windrose.WindRosePlot.java

@Override
public LegendItemCollection getLegendItems() {
    ///*from www .  j ava  2 s  .  co  m*/
    // Create the legend item to differentiate the speed bins
    //
    LegendItemCollection items = new LegendItemCollection();

    LegendItem defaultItem = new LegendItem("Dummy");

    if (data != null) {
        List<SpeedBin> bins = data.getSpeedBins();

        for (int j = 0; j < bins.size(); j++) {
            LegendItem item = new LegendItem(bins.get(j).speedString(), "Speed Bin", "", "",
                    defaultItem.getShape(), binColor[j], defaultItem.getOutlineStroke(),
                    defaultItem.getOutlinePaint());

            items.add(item);
        }
    }
    return items;
}