Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从java中的折线图中获取值?_Java_Jfreechart - Fatal编程技术网

如何从java中的折线图中获取值?

如何从java中的折线图中获取值?,java,jfreechart,Java,Jfreechart,如何获得点Y=60的X轴(hotrizontal)上的值?方法.getAnnotationX()和.getAnnotationY()不起作用,不知道为什么(找不到方法)。有人能帮我吗?如果60是XYSeries中某个点的坐标,您只需搜索getItems()返回的列表,并找到相应的横坐标即可。因为不是,所以需要搜索括号点-(0.25,50)和(0.5,80)。然后,您可以使用Regression.getOLSRegression()方法查找连接两点的直线的斜率和截距。给定这些值,可以求解相应的横坐


如何获得点Y=60的X轴(hotrizontal)上的值?方法
.getAnnotationX()
.getAnnotationY()
不起作用,不知道为什么(
找不到方法
)。有人能帮我吗?

如果
60
XYSeries
中某个点的坐标,您只需搜索
getItems()
返回的
列表
,并找到相应的横坐标即可。因为不是,所以需要搜索括号点-
(0.25,50)
(0.5,80)
。然后,您可以使用
Regression.getOLSRegression()
方法查找连接两点的直线的斜率和截距。给定这些值,可以求解相应的横坐标。或者,您可以重新排列线性方程的顺序,以找到所需的点。下面显示了一个使用
Regression.getOLSRegression()
的完整示例

public class createLineChartForSandSoil {

    static JFreeChart chart;
    public static XYSeries series;

    public static void createLineChartForSandSoil(Document document) throws DocumentException, BadElementException, IOException {
        Paragraph wordDegreeOfHeterogeneity = new Paragraph("Визначаємо ступінь неоднорідності піску:", smallFont);
        document.add(wordDegreeOfHeterogeneity);

        ChartPanel chartPanel = createChartPanel();
        int width = 450;
        int height = 350;
        XYPlot plot = chart.getXYPlot();
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setSeriesPaint(0, Color.BLACK);
        plot.setRenderer(renderer);
        plot.setOutlinePaint(Color.WHITE);
        plot.setBackgroundPaint(Color.WHITE);
        plot.setRangeGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.GRAY);
        plot.setDomainGridlinesVisible(true);
        plot.setDomainGridlinePaint(Color.GRAY);

        File lineChart = new File("D:/LineChart.png");
        ChartUtilities.saveChartAsPNG(lineChart, chart, width, height);
        Image img = Image.getInstance("D:/LineChart.png");
        img.scalePercent(60f);
        document.add(img);
    }

    private static XYDataset createDataset() {
        XYSeriesCollection dataset = new XYSeriesCollection();
        series = new XYSeries("");

        series.add(2.0, sumOfParticlesLess_ValueMoreThan2);
        series.add(1.0, sumOfParticlesLess_Value1_2);
        series.add(0.5, sumOfParticlesLess_Value05_1);
        series.add(0.25, sumOfParticlesLess_Value025_05);
        series.add(0.1, sumOfParticlesLess_Value01_025);
        series.add(0.0, 0.0);

        dataset.addSeries(series);

        return dataset;
    }

    private static ChartPanel createChartPanel() {
        String chartTitle = "";
        String xAxisLabel = "Діаметр частинок d, мм";
        String yAxisLabel = "Сума частинок, %";

        XYDataset dataset = createDataset();

        chart = ChartFactory.createXYLineChart(chartTitle, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, false, false, false);

        return new ChartPanel(chart);
    }  
}