【问题标题】:Plotting a hysteresis loop with jFreeChart用 jFreeChart 绘制磁滞回线
【发布时间】:2013-02-20 04:53:53
【问题描述】:

我需要绘制磁滞回线,然后计算回环内的闭合面积。我正在使用 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();
   }

它给了我以下结果:

如果我使用:

 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
);

我给:

我需要一个如下所示的滞后图:

我想不同之处在于点的连接方式。请指导如何使用jFreeChart获得所需的磁滞回线以及如何计算封闭面积。

谢谢

【问题讨论】:

  • 您可以绘制两条 XY 线:一条用于较高的线,一条用于较低的线。
  • @assylias 有没有其他解决方案,而不是使用两行。我需要为 hyst[23] 获得的不同读数绘制许多这样的滞后图,并且需要将它们叠加在同一张图上并比较封闭区域的变化..
  • 提到了一些关于区域的想法here

标签: java jfreechart


【解决方案1】:

如何更改线条颜色以及代表数据点的符号。我希望它们都统一。

看来您已选择JFreeChart 供您查看。综合其他几个cmets,

  • 您可以通过提供DrawingSupplier 来使多个系列的颜色和形状同质化,如建议的here 和显示的here

  • 您可以将系列组合成一个GeneralPath,并按照here 的轮廓估计面积。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多