java - 使用 jFreeChart 绘制磁滞回线

标签 java jfreechart

我需要绘制磁滞回线,然后计算回线内闭合的面积。我正在使用 jFreeChart。

考虑以下数据:

 hyst[0]=0;
       hyst[1]=0;
       hyst[2]=0.0098;
       hyst[3]=0.0196;
       hyst[4]=0.0489;
       hyst[5]=0.0879;
       hyst[6]=0.0684;
       hyst[7]=0.0489;
       hyst[8]=0.0196;
       hyst[9]=0.0098;
       hyst[10]=0;
       hyst[11]=0;
       hyst[12]=0;
       hyst[13]=0;
       hyst[14]=0;
       hyst[15]=-0.0195;
       hyst[16]=-0.0488;
       hyst[17]=-0.0391;
       hyst[18]=-0.0195;
       hyst[19]=0;
       hyst[20]=0;

当我尝试时:

   public void plotHysteresis()
   {
       int j=0;
       int i=0;
       XYSeries series1 = new XYSeries("Before Treatment");
      // DefaultCategoryDataset series1 = new DefaultCategoryDataset();
       for(i=0;i<6;i++)
       {    
        series1.add(j,hyst[i]);
        logTextArea.append(Integer.toString(j) +" : " +Double.toString(hyst[i])+"\n");
        j=j+5;
       }
       j=j-5; 
       for(;i<11;i++)
       {
        j=j-5;   
        series1.add(j,hyst[i]);
        logTextArea.append(Integer.toString(j) +" : " +Double.toString(hyst[i])+"\n");
       }
        for(;i<16;i++)
       {
        j=j-5;   
        series1.add(j,hyst[i]);
        logTextArea.append(Integer.toString(j) +" : " +Double.toString(hyst[i])+"\n");
       }
           for(;i<21;i++)
       {
        j=j+5;   
        series1.add(j,hyst[i]);
        logTextArea.append(Integer.toString(j) +" : " +Double.toString(hyst[i])+"\n");
       }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series1);

    JFreeChart chart = ChartFactory.createXYAreaChart(
"Hysteresis Plot", // chart title
"Pounds (lb)", // x axis label
"Distance (inches)", // y axis label
dataset, // data
PlotOrientation.VERTICAL,
true, // include legend
true, // tooltips
false // urls
);
    chart.setBackgroundPaint(Color.white);

    ChartPanel frame = new ChartPanel(chart);
    frame.setVisible(true);
    frame.setSize(plotPanel.getWidth(),plotPanel.getHeight());
    plotPanel.add(frame);
    plotPanel.repaint();
   }

它给了我以下结果:

enter image description here

如果我使用:

 JFreeChart chart = ChartFactory.createXYLineChart(
"Hysteresis Plot", // chart title
"Pounds (lb)", // x axis label
"Distance (inches)", // y axis label
dataset, // data
PlotOrientation.VERTICAL,
true, // include legend
true, // tooltips
false // urls
);

我给出:

enter image description here

我需要一个如下所示的磁滞图: enter image description here

我想区别在于点的连接方式。请指导如何使用jFreeChart获得所需的磁滞回线,然后如何计算封闭的面积。

谢谢

最佳答案

How can I change the line color as well the symbols representing the data points. I want all of them to be uniform.

看来您已选择使用 JFreeChart 作为 View 。综合一些其他评论,

  • 您可以通过提供 DrawingSupplier 使多个系列的颜色和形状保持一致,如建议的 here并显示here .

  • 您可以将该系列组合成 GeneralPath并按照概述估计面积 here .

关于java - 使用 jFreeChart 绘制磁滞回线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14952712/

相关文章:

java - 如何只为他的 parent 制作 JDialog onTop?

java - 使用 Java 配置的 Spring 4 REST 应用程序(无 xml) IllegalArgumentException

Java:方法 Integer.toString() 比将空字符串添加到整数类型值更好吗?

java - 为什么文本文件没有完全读取?

java - 如何在 JFreeChart 中将 ChartPanel 坐标转换为 XYPlot 坐标

charts - 用于显示最小值/最大值/平均值的条形图

java - 如何使用 CP1250 编码将自定义字体添加到 JFreeChart

具有双 x 轴的 JFreeChart

java - 如何使用 apache POI 和 java 比较 2 个不同的 excel.xls 工作表

java - 单击折线图上的点时获取值