Jfree chart change Y axis data

怎甘沉沦 提交于 2019-12-24 17:29:57

问题


I am using Jfree chart 0.9.20's XYLineChartDemo for plotting the execution time of running processes in a program. My X axis denotes the time and Y axis should denote the Pid. How can I edit the Jfreechart files to make my Y axis to denote values I want and not numbers 0-range?? Also is there a way to make the line plotted to be made thicker in width?


回答1:


study this:

public JFreeChart createChart(String axisX, String axisY){

    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, axisX, axisY, dataSeries, true, true, false);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0,true);
    renderer.setSeriesShapesVisible(0, true);

    //percentage (y-axis)
    final NumberAxis percentAxis = new NumberAxis(axisY);
    percentAxis.setInverted(false);
    percentAxis.setRange(0.0, 100.0);

    //time (x-axis)
    final DateAxis timeAxis = new DateAxis(axisX);
    timeAxis.setStandardTickUnits(DateAxis.createStandardDateTickUnits(TimeZone.getDefault(), Locale.ENGLISH));

    double range = 0;

    switch (format){
        case ONE_MINUTE_RANGE: range = 60*1000; break;
        case TEN_MINUTE_RANGE: range = 10*60*1000; break;
        case ONE_HOUR_RANGE: range = 60*60*1000; break;
    }

    timeAxis.setRange(System.currentTimeMillis()-range/2, System.currentTimeMillis()+range/2); //time duration based on format chosen

    XYPlot plot = chart.getXYPlot();
    plot.setDomainAxis(timeAxis);
    plot.setRangeAxis(percentAxis);

    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setRangeZeroBaselinePaint(Color.gray);
    plot.setDomainGridlinePaint(Color.gray);
    plot.setForegroundAlpha(0.5f);
    plot.setRenderer(renderer);

    chart.setBackgroundPaint(Color.white);

    return chart;
}


来源:https://stackoverflow.com/questions/5281218/jfree-chart-change-y-axis-data

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