CandleStick e Media movel JFreeChart

0 respostas
F

aee,

Estou com problemas para fazer com que tenha CandleStick e a linha da media movel no mesmo grafico. Aqui esta o codigo que plota os Candles, nao consigo fazer a linha da media movel aparecer no mesmo grafico. alguem sabe como fazer isso ?

public class LineChartDemo1 extends ApplicationFrame 
{

	private static JFreeChart chart;

	public LineChartDemo1(final String title) {
		super(title);
		
	}

	public static void main(String[] args)
	{

		LineChartDemo1 demo = new LineChartDemo1("Line Chart Demo");
		
		DefaultHighLowDataset dataset = createDataset2();

		chart = ChartFactory.createCandlestickChart("Candle", "timeaxis", "valueaxis", dataset, true);
		final ChartPanel chartPanel = new ChartPanel(chart);
		chartPanel.setPreferredSize(new Dimension(500, 270));
		demo.setContentPane(chartPanel);
		demo.pack();
		RefineryUtilities.centerFrameOnScreen(demo);
		demo.setVisible(true);// create the chart...

	}

	
	private static Date createData(int year, int month, int date) 
        {
		Calendar calendar = Calendar.getInstance();
		calendar.set(year, month - 1, date);
		return calendar.getTime();
	}

	private static DefaultHighLowDataset createDataset2() 
       {

		int serice = 30;

		Date[] date = new Date[serice];
		double[] high = new double[serice];
		double[] low = new double[serice];
		double[] open = new double[serice];
		double[] close = new double[serice];
		double[] volume = new double[serice];

		Calendar calendar = Calendar.getInstance();
		calendar.set(2008, 5, 1);

		for (int i = 0; i < serice; i++) {
			date[i] = createData(2008, 8, i + 1);
			high[i] = 30 + Math.round(10) + new Double(Math.random() * 20.0);
			low[i] = 30 + Math.round(10) + new Double(Math.random() * 20.0);
			open[i] = 10 + Math.round(10) + new Double(Math.random() * 20.0);
			close[i] = 10 + Math.round(10) + new Double(Math.random() * 20.0);
			volume[i] = 10.0 + new Double(Math.random() * 20.0);
		}

		DefaultHighLowDataset data = new DefaultHighLowDataset("", date, high,
				low, open, close, volume);
		return data;
	}
}
Criado 27 de novembro de 2010
Respostas 0
Participantes 1