用Java创建时尚的图表,例如使用JFreeChart

use*_*466 7 java charts styles jfreechart

在Java中创建漂亮图表的最佳方法是什么?看起来图表的主要选项是JFreeChart,但不幸的是,默认情况下它们看起来非常简单.

将JFreeChart的示例:http://www.jfree.org/jfreechart/images/PriceVolumeDemo1.png 与其中一个Javascript图表库进行比较,例如http://www.highcharts.com/demo/spline-symbols/gridhttp://people.iola.dk/olau/flot/examples/graph-types.html

javascript看起来更好 - 它们有流畅的线条,默认情况下字体很好,而且与JFreeChart相比整体看起来很好看,看起来非常简单.

是否有一个建立在JFreeChart之上的图表库,默认情况下看起来不错,或者是一些示例代码可以使普通的JFreeChart图表(例如折线图)看起来很棒?

Rob*_*bAu 11

我遇到过同样的问题.

此代码使JFreeChart看起来像Highcharts(目前仅支持条形图).它可以很容易地变得更有效:)

    String fontName = "Lucida Sans";
    JFreeChart chart = ChartFactory.createBarChart(null, "", "", dataset, PlotOrientation.VERTICAL, false, true, false );

    StandardChartTheme theme = (StandardChartTheme)org.jfree.chart.StandardChartTheme.createJFreeTheme();

    theme.setTitlePaint( Color.decode( "#4572a7" ) );
    theme.setExtraLargeFont( new Font(fontName,Font.PLAIN, 16) ); //title
    theme.setLargeFont( new Font(fontName,Font.BOLD, 15)); //axis-title
    theme.setRegularFont( new Font(fontName,Font.PLAIN, 11));
    theme.setRangeGridlinePaint( Color.decode("#C0C0C0"));
    theme.setPlotBackgroundPaint( Color.white );
    theme.setChartBackgroundPaint( Color.white );
    theme.setGridBandPaint( Color.red );
    theme.setAxisOffset( new RectangleInsets(0,0,0,0) );
    theme.setBarPainter(new StandardBarPainter());
    theme.setAxisLabelPaint( Color.decode("#666666")  );
    theme.apply( chart );
    chart.getCategoryPlot().setOutlineVisible( false );
    chart.getCategoryPlot().getRangeAxis().setAxisLineVisible( false );
    chart.getCategoryPlot().getRangeAxis().setTickMarksVisible( false );
    chart.getCategoryPlot().setRangeGridlineStroke( new BasicStroke() );
    chart.getCategoryPlot().getRangeAxis().setTickLabelPaint( Color.decode("#666666") );
    chart.getCategoryPlot().getDomainAxis().setTickLabelPaint( Color.decode("#666666") );
    chart.setTextAntiAlias( true );
    chart.setAntiAlias( true );
    chart.getCategoryPlot().getRenderer().setSeriesPaint( 0, Color.decode( "#4572a7" ));
    BarRenderer rend = (BarRenderer) chart.getCategoryPlot().getRenderer();
    rend.setShadowVisible( true );
    rend.setShadowXOffset( 2 );
    rend.setShadowYOffset( 0 );
    rend.setShadowPaint( Color.decode( "#C0C0C0"));
    rend.setMaximumBarWidth( 0.1);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


her*_*tim 9

试试XChart.XChart是一个轻量级的Java库,用于绘制数据,这些数据可能是JFreeChart的替代品.它的重点是简单性,并不具备JFreeChart所具有的所有功能,但它提供了丰富的图表功能,包括主题,可以将不同的"皮肤"应用于图表.您可以通过实现接口并通过调用将其应用于图表来轻松创建自己的主题chart.setTheme(myTheme).从2.0.0版本开始,jar只有~86 KB,并且它没有依赖关系.它在Apache 2.0下获得许可,并在Github上托管.一些截图可以在这里找到.免责声明:我是该项目的主要开发人员.

在此输入图像描述


Ben*_*min 3

http://www.jfree.org/jfreechart/samples.html

在那里您可以找到许多示例(您需要下载 JFreeChart Demo(网络启动))。使用 jFreeChart 进行一些工作后,我正在考虑转向 EasyChart(请关注: http: //www.objectplanet.com/easycharts/examples.html),但实际上它看起来与 jFreeChart 非常相似。JFreeChart很容易编写,我不知道EasyChart。

但根据你的问题,在 JFreeChart 中更改 Font、LineRenderer 或任何设计都没有问题,因此你可以修改它,使其看起来与你从 JavaScript 发布的一模一样。