JFreechart - XY步骤图范围和精度问题

时间:2011-11-25 01:57:42

标签: java charts jfreechart

我正在尝试分别使用以下X和Y值创建XY步骤图。但是,我几乎没有问题

  1. X和Y轴的范围太粒度,因此未显示图表上的所有数据点。我怎样才能自己设定范围和精度?
  2. 我很困惑为什么X轴范围显示为 19:00:00:025 。这与我添加的数据项不匹配。
  3. 代码

    final XYSeries series = new XYSeries("Random Data");
    
            for (Coordinate c : coordinates)
            {
                series.add(c.x, c.y);
            }
    
            final XYSeriesCollection data = new XYSeriesCollection(series);
    
            final JFreeChart chart = ChartFactory.createXYStepChart("XY Series Demo", "Latitude.before " + builder.getBeforeSimplifySize(),
                    "Longitude.after " + builder.getAfterSimplifySize(), data, PlotOrientation.VERTICAL, true, true, false);
    
            XYPlot plot = (XYPlot) chart.getPlot();
            XYSplineRenderer renderer = new XYSplineRenderer();
            renderer.setSeriesLinesVisible(0, true);
            renderer.setSeriesShapesVisible(0, true);
            renderer.setSeriesLinesVisible(1, false);
            renderer.setSeriesShapesVisible(1, true);
            plot.setRenderer(renderer);
            final ChartPanel chartPanel = new ChartPanel(chart);
            chartPanel.setPreferredSize(new java.awt.Dimension(1000, 1000));
    
            setContentPane(chartPanel);
    

    图表图片

    enter image description here

    数据(X,Y)

    22.11845833328035, 21.7640694448683
    22.118927777873147, 21.767827777730094
    22.119402777883742, 21.771577777862547
    22.11986111111111, 21.775330555703903
    22.120297222137452, 21.779052777820162
    22.1207694445716, 21.782777777777778
    22.12122777779897, 21.786499999894037
    22.121691666709054, 21.790222222010296
    22.12238333331214, 21.793791667090524
    22.124313889079623, 21.794461111492584
    22.125488888952468, 21.792299999660916
    22.126555555131702, 21.789572221967912
    22.127716666327583, 21.786597222222223
    22.128902777565852, 21.78352499999934
    22.12928055551317, 21.780111111534964
    22.12799444410536, 21.777344444062972
    22.126263888676963, 21.77588611072964
    22.1247833331426, 21.774636111259458
    22.12351944446564, 21.77356666670905
    22.12268888897366, 21.77209999985165
    22.12205555544959, 21.770461111068723
    22.12130833307902, 21.76895277765062
    22.120730555587347, 21.76736111111111
    22.12099722226461, 21.76573333316379
    22.121925000084772, 21.765163888931273
    22.122738889058432, 21.765847222010294
    22.12294444455041, 21.767177777787047
    22.12261111100515, 21.76862500005298
    22.12194166660309, 21.76981666670905
    22.120891666677263, 21.769922222296398
    22.1201444445716, 21.76878055559264
    22.119852777851953, 21.767180555562177
    22.11962222231759, 21.76557499991523
    22.11872777779897, 21.7645194445716
    22.11762222223812, 21.76518888897366
    22.117516666650772, 21.767211111121707
    22.118702777756585, 21.7682361111376
    22.120177777873145, 21.76688611111707
    22.11994166665607, 21.764588889016046
    22.118886111047534, 21.76399722205268
    22.117880555523765, 21.763383333418105
    22.11763333333863, 21.762047221925524
    22.1186000000106, 21.760833333333334
    22.1199277777142, 21.760519444147747
    22.12074999994702, 21.75909999953376
    22.120244444476235, 21.757891666624282
    22.119372222158646, 21.757316666709052
    22.118452777730095, 21.756691666709052
    22.118022222254012, 21.75526111125946
    22.11852222217454, 21.75406388892068
    22.119263888994855, 21.75299444437027
    22.119561111132306, 21.751650000015896
    22.118716666698457, 21.75051666667064
    22.117644444439147, 21.75164722217454
    22.118058333396913, 21.7530166665713
    22.118777777751287, 21.7538583334287
    22.119766666624283, 21.754372222158644
    22.12112777762943, 21.75402777777778
    22.122155555619134, 21.75211111108462
    22.121849999957615, 21.749758333630034
    22.12074166668786, 21.748875000211928
    22.119677777820165, 21.748883333206177
    22.118625000052983, 21.748944444656374
    22.11725277774864, 21.74952222188314
    22.116283333036638, 21.751622222264608
    22.116841666665344, 21.75414166662428
    22.11861111111111, 21.75535000006358
    22.12064722220103, 21.756391666730245
    22.122597222328185, 21.757097222010295
    22.124005555576748, 21.756288888719347
    24.125258333418106, 23.755583333439297
    26.12644444465637, 25.754974999957614
    28.127694444656374, 27.754299999872842
    29.129219444062976, 28.75346111112171
    30.130997222264607, 29.752511111100514
    31.13303055551317, 30.75141111108992
    35.13517777774069, 34.75021666665872
    36.13741666661368, 35.74901111072964
    39.13970833354526, 38.747786110772026
    40.14173888895247, 39.74669444402059
    

1 个答案:

答案 0 :(得分:4)

ChartFactory.createXYStepChart使用DateAxis作为域名; 22.1附近的值将相应地接近时期。您可能想要使用NumberAxis

范围是NumberAxis,看起来像预期的那样。您可以使用父ValueAxis中的同名方法更改边界。