首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用jFreeChart绘制磁滞回线

用jFreeChart绘制磁滞回线
EN

Stack Overflow用户
提问于 2013-02-19 16:10:31
回答 1查看 890关注 0票数 1

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

考虑以下数据:

代码语言:javascript
复制
 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;

当我尝试的时候:

代码语言:javascript
复制
   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();
   }

它给了我以下结果:

如果我使用:

代码语言:javascript
复制
 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获得所需的磁滞回线,以及如何计算封闭面积。

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-20 04:53:54

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

看起来你已经为你的视图选择了JFreeChart。综合其他一些评论,

  • 你可以通过提供一个DrawingSupplier来使你的几个系列的颜色和形状均匀,如建议的herehere.
  • You所示,你可以将这些系列组合到一个中,并估计如here.

所示的面积

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14952712

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档