2013年9月15日日曜日

Add chart objects

Add chart objects
チャートオブジェクトの追加

One can not only plot chart objects from within a strategy, but also from the program running IClient.
ストラテジの中からチャートオブジェクトをプロットできるだけではなく、IClient実行中のプログラムからも可能である。
Consider creating a button panel which receives an IChart from IClientGUI.getChart():
IClientGUI.getChart()からIChartを受信するボタンパネルの作成を検討して欲しい。 

@SuppressWarnings("serial")
private class ChartObjectPanel extends JPanel {
   
    private final IChart chart;
    private ChartObjectPanel(IChart chart){
        this.chart = chart;
        addButtons();
    }
   
    private void addButtons(){          
        JButton btnVLine = new JButton("Add VLine");
        btnVLine.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e) {
                //draw the line at the time of the last drawn feed element on the chart
                ITimedData[] chartData = chart.getLastRequestedData();
                long time = chartData[chartData.length - 1].getTime();
                IChartObject obj = chart.getChartObjectFactory().createVerticalLine("vLine", time);
                obj.setColor(Color.RED);
                chart.add(obj);
            }});
        add(btnVLine);          
        JButton btnHLine = new JButton("Add HLine");
        btnHLine.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e) {  
                //draw the line in the chart price axis midpoint
                double price = chart.getMinPrice() + (chart.getMaxPrice() - chart.getMinPrice()) / 2;
                System.out.println(String.format("%.5f", price));                  
                IChartObject obj = chart.getChartObjectFactory().createHorizontalLine("hLine", price);
                obj.setColor(Color.GREEN);
                chart.add(obj);
            }});
        add(btnHLine);
    }
   
}

0 件のコメント:

コメントを投稿