JFreeChart设置系列的Alpha值

时间:2018-08-20 10:22:13

标签: java jfreechart

我创建了一个具有双y轴的面积图。我总体上有4个系列。在面积图的基础上显示了两个系列,而另两个系列则显示为一条线。现在我的问题是,我想将前两个系列的alpha值设置得较低,以便使两个线系列更清晰可见,或者是否可以设置z顺序或其他方式?

private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createAreaChart("eafedo5", // chart title
            "", // domain axis label
            "Messages/Second", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.BLACK);

    // set the background color for the chart...
    // final StandardLegend legend = (StandardLegend) chart.getLegend();
    // legend.setAnchor(StandardLegend.SOUTH);

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setForegroundAlpha(0.5f);
    plot.setBackgroundPaint(Color.DARK_GRAY);
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    final CategoryDataset dataset2 = createDatasetBytes();
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);

    final ValueAxis valueAxis2 = new NumberAxis("Bytes/Second");
    plot.setRangeAxis(1, valueAxis2);
    valueAxis2.setAxisLinePaint(Color.white);
    valueAxis2.setTickLabelPaint(Color.white);
    valueAxis2.setLabelPaint(Color.white);

    final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    //renderer2.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    plot.setRenderer(1, renderer2);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);


    final ValueAxis valueAxis = plot.getRangeAxis();
    valueAxis.setAxisLinePaint(Color.white);
    valueAxis.setTickLabelPaint(Color.white);
    valueAxis.setLabelPaint(Color.white);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setVisible(true);
    domainAxis.setAxisLinePaint(Color.white);
    domainAxis.setTickLabelPaint(Color.white);
    domainAxis.setLabelPaint(Color.white);


    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLabelAngle(0 * Math.PI / 2.0);

    CategoryItemRenderer renderer1 = plot.getRenderer();
    renderer1.setSeriesPaint(0, Color.WHITE);
    renderer1.setSeriesPaint(1, Color.LIGHT_GRAY);

    renderer2.setSeriesPaint(0, Color.YELLOW);
    renderer2.setSeriesPaint(1, Color.GREEN);

    return chart;

}

我搜索了可以设置Alpha值但找不到任何内容的方法。为了更好地说明这一点,我添加了以下图表:Area Chart

0 个答案:

没有答案