vxdvcv 2019-06-12 09:40 采纳率: 100%
浏览 241
已采纳

jfreechart的散点图竖轴数据反了是什么原因?

图片说明
********************代码*******************************
public class Panal_gong extends JPanel implements ActionListener{

private static final long serialVersionUID = -5628586708228044760L;
public   static DatePicker  field_wave =null ;
public   static DatePicker field2_wave=null;
private  JButton button_seasrch =null;//搜索按钮
private  static JFreeChart mChart =null;//图表
private static BorderLayout borderLayout = new BorderLayout();
private WellDynamics wd;

public static JFreeChart getmChart() {
    return Panal_gong.mChart;
}

public WellDynamics getWd() {
    return wd;
}

public void setWd(WellDynamics wd) {
    this.wd = wd;
}

public static void setmChart(JFreeChart mChart) {
    Panal_gong.mChart = mChart;
}



public Panal_gong() {
    initComponents();
    // 确保一个漂亮的外观风格
}

public Panal_gong(WellDynamics wave) throws HeadlessException {
    super();
    this.setLayout(borderLayout);//设置布局管理器
    this.setWd(wave);
    ChartPanel cf = new ChartPanel (createChart(""));
    /*ChartPanel添加节点鼠标点击事件,节点上没找到鼠标点击事件*/

// cf.addChartMouseListener(new MyXYLineChartListener(wave)); //MyXYLineChartListener
this.add(cf,BorderLayout.CENTER) ;
}

/**
 * 创建数据集合
 * @return dataSet
 */
private static XYDataset createDataset(List<Double> list1,List<Double> list2,List<Double> list3) {
    final XYSeries xyseries = new XYSeries("位移-载荷");
    final XYSeries maxSeries = new XYSeries("最大载荷:"+ Collections.max(list2)+"KN");
    final XYSeries minSeries = new XYSeries("最小载荷:"+Collections.min(list2)+"KN");
    XYSeries cc0Series = null;
    XYSeries cc1Series = null;
    if(list3.size()>0){
        cc0Series = new XYSeries("冲次:"+list3.get(list3.size()-2));
        cc1Series = new XYSeries("冲程:"+list3.get(list3.size()-1));
    }
    xyseries.add(0, null);//原点坐标的值
    if(null != list1){
        for (int i = 0; i < list1.size(); i++) {
            xyseries.add(list1.get(i), list2.get(i));
        }
    }
    final XYSeriesCollection xyseriescollection = new XYSeriesCollection();
    xyseriescollection.addSeries(xyseries);
    xyseriescollection.addSeries(maxSeries);
    xyseriescollection.addSeries(minSeries);
    if(null != cc0Series && null != cc1Series) {
        xyseriescollection.addSeries(cc0Series);
        xyseriescollection.addSeries(cc1Series);
    }

    return xyseriescollection;
}


/**
 * 初始化界面
 */
private void initComponents() {
    BorderLayout borderLayout = new BorderLayout();
    this.setLayout(borderLayout);
    //画功图
    this.add(initTime(),BorderLayout.NORTH);
    ChartPanel cf = new ChartPanel (createChart(""));
    this.add(cf,BorderLayout.CENTER) ;
}

/*
 * 初始化头部的时间控件
 * */
private  JPanel initTime (){
    FlowLayout flowLayout = new FlowLayout();
    JPanel panel_top = new JPanel(flowLayout);
    Label label = new Label("起止时间");
    Label label2 = new Label("终止时间");
    Panal_gong.field_wave = CreateDatePikerDilog.getDatePicker();
    Panal_gong.field2_wave = CreateDatePikerDilog.getDatePicker();
    this.button_seasrch = new JButton("搜索");
    this.button_seasrch.addActionListener(this);
    panel_top.add(label);
    panel_top.add(Panal_gong.field_wave);
    panel_top.add(label2);
    panel_top.add(Panal_gong.field2_wave);
    panel_top.add(button_seasrch);
    return panel_top;
}


// 返回char对象
private JFreeChart createChart(String title){
    //下面是代码
    StandardChartTheme mChartTheme = new StandardChartTheme("CN");
    mChartTheme.setExtraLargeFont(new Font("隶书", Font.BOLD, 25)); //设置标题字体  
    mChartTheme.setRegularFont(new Font("宋体", Font.PLAIN, 15)); //设置图例的字体  
    mChartTheme.setLargeFont(new Font("宋体", Font.PLAIN, 20)); //设置轴向的字体  
    ChartFactory.setChartTheme(mChartTheme);        
    XYDataset mDataset = createDataset(wd.getxList(),wd.getyList(),wd.getzList());
    Panal_gong.mChart = ChartFactory.createScatterPlot(
            title +"井口功图",
            "位移(m)",
            "载荷(KN)",
            mDataset,
            PlotOrientation.VERTICAL,
            true, 
            true, 
            false);
    /**
     * 影藏掉图列的位置
     */
    Panal_gong.mChart.getLegend().setBorder(0, 0, 0, 0);
    XYPlot mPlot = Panal_gong.mChart.getXYPlot();
    NumberAxis numberaxis = (NumberAxis) mPlot.getRangeAxis();
    numberaxis.setInverted(true); 
    mPlot.setDataset(1, null);//添加一个数据源
    mPlot.mapDatasetToRangeAxis(1, 1);  //默认在主轴显示数据,这个方法改变数据源显示轴的位置

    ValueAxis valueAxis = mPlot.getRangeAxis();// 设置数据轴对象
    valueAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
    ValueAxis loadAxis = mPlot.getDomainAxis();
    loadAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
    return mChart;

}

@Override
public void actionPerformed(ActionEvent e) {
    Object en = e.getSource();
    if (this.button_seasrch.equals(en)) { //搜索按钮
        QueryDatabyLeftAndContent.searchDynaPage(1);
    }

}

}

  • 写回答

1条回答 默认 最新

  • vxdvcv 2019-06-12 10:31
    关注

    numberaxis.setInverted(false//反转竖轴

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条