แกนโดเมน JFree แบบเลื่อนได้และป้ายกำกับเครื่องหมายแบบกำหนดเอง

ฉันมีรหัสนี้ในการวาดกราฟ มันใช้งานได้ดี ฉันต้องการสองสิ่งที่นี่

  1. บนแกนโดเมน (x) ฉันต้องการเลื่อนได้
  2. บนเครื่องหมายฉันเห็นเส้นหนา ฉันต้องการที่จะเห็นข้อความที่อ่านได้สำหรับเครื่องหมายนี้

ตอนนี้ฉันเห็นเอาต์พุตนี้ ป้อนคำอธิบายรูปภาพที่นี่

และเมื่อซูมเข้าไปก็เห็นสิ่งนี้

ป้อนคำอธิบายรูปภาพที่นี่

  1. นอกจากนี้บนแกนโดเมน ฉันมีค่าเป็นมิลลิวินาทีด้วย ฉันสามารถแมปมันกับวันที่ที่มนุษย์อ่านได้หรือไม่

    public class Grapher extends ApplicationFrame {
    
        public Grapher(final String title, List<PriceModel> priceModels) {
    
            super(title);
            final XYSeries series = new XYSeries("foo");
            double max = Double.MIN_VALUE, min = Double.MAX_VALUE;
            for (int i = 0; i < priceModels.size(); i++) {
                double price = priceModels.get(i).getPrice();
                if (price < min) {
                    min = price;
                }
                if (price > max) {
                    max = price;
                }
                series.add((double) priceModels.get(i).getDate(), price);
            }
    
            final XYSeriesCollection data = new XYSeriesCollection(series);
            final JFreeChart chart = ChartFactory.createXYLineChart(
                    "XY Series Demo",
                    "X",
                    "Y",
                    data,
                    PlotOrientation.VERTICAL,
                    true,
                    true,
                    false
            );
    
            for (int i = 0; i < priceModels.size(); i++) {
                if (priceModels.get(i).getAction() != null) {
                    Marker marker = new ValueMarker((double) priceModels.get(i).getDate());
                    marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
                    marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
    
                    if (priceModels.get(i).getAction() == Types.Action.SELL) {
                        marker.setPaint(Color.green);
                        marker.setLabel("SELL");
                    } else {
                        marker.setPaint(Color.red);
                        marker.setLabel("BUY");
                    }
                    marker.setStroke(new BasicStroke(10.0f));
                    chart.getXYPlot().addDomainMarker(marker);
                }
            }
            chart.getXYPlot().setBackgroundPaint(Color.white);
            chart.getXYPlot().getRenderer().setPaint(Color.BLUE);
            chart.getXYPlot().getRangeAxis().setRange(min - 1, max + 1);
            final ChartPanel chartPanel = new ChartPanel(chart);
            chartPanel.setBackground(Color.WHITE);
            chartPanel.setRangeZoomable(true);
            chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
            setContentPane(chartPanel);
        }
    
        public static void draw(List<PriceModel> priceModels) {
            final Grapher demo = new Grapher("foo", priceModels);
            demo.pack();
            RefineryUtilities.centerFrameOnScreen(demo);
            demo.setVisible(true);
        }
    }
    

person user3833308    schedule 22.05.2017    source แหล่งที่มา
comment
คุณได้ลองใส่ chartPane ใน JScrollPane แล้วหรือยัง?   -  person MadProgrammer    schedule 22.05.2017
comment
@MadProgrammer ฉันจะทำอย่างไร?   -  person user3833308    schedule 22.05.2017
comment
วิธีใช้บานหน้าต่างเลื่อน   -  person MadProgrammer    schedule 22.05.2017
comment
@MadProgrammer: ฉันจะดูสิ่งอื่นสองสามอย่างก่อนบานหน้าต่างเลื่อน เพิ่มเติมด้านล่าง   -  person trashgod    schedule 22.05.2017
comment
@trashgod ต้องยอมรับว่าฉันไม่ได้ใช้ JFreeChart จริงๆ   -  person MadProgrammer    schedule 22.05.2017


คำตอบ (1)


คุณจะต้องรวมหลายแนวทางเข้าด้วยกัน:

  1. ทางเลือกในการเลื่อนโดเมน:

  2. ข้อความมาร์กเกอร์: ใช้ XYTextAnnotation สำหรับตัวอย่าง

  3. จัดรูปแบบวันที่: แทนที่แกนของโรงงานด้วย DateAxis และใช้ setDateFormatOverride() สำหรับตัวอย่าง

person trashgod    schedule 22.05.2017
comment
คุณกำลังแนะนำให้ใช้การเลื่อนทั้ง 4 จุดหรือนี่เป็นตัวเลือก? - person user3833308; 23.05.2017
comment
พวกเขาเป็นตัวแทนของทางเลือก; ปกติฉันจะเปิดใช้งานการแพนเท่านั้น - person trashgod; 23.05.2017
comment
ขอบคุณ ในกรณีของฉันเวลาอยู่บนแกน X อนุญาตให้ใช้ DateAxis บน Y เท่านั้น - person user3833308; 24.05.2017
comment
ฉันไม่เข้าใจ. การใช้งาน SlidingXYDataset ที่อ้างถึงข้างต้นจะแสดง NumberAxis ในการสาธิตครั้งแรกและ DateAxis ในการสาธิตครั้งที่สอง ทั้งสองเป็นแกนโดเมน - person trashgod; 24.05.2017
comment
ขอบคุณ @trashgod คุณสามารถช่วยที่นี่ได้เช่นกัน stackoverflow com/questions/44150322/ ? - person user3833308; 24.05.2017