/** * Creates and returns a default instance of a high-low-open-close chart with * a special timeline. This timeline can be a {@link org.jfree.chart.axis.SegmentedTimeline} * such as the Monday trough Friday timeline that will remove Saturdays and Sundays from * the axis. * * @param title the chart title (<code>null</code> permitted). * @param timeAxisLabel a label for the time axis (<code>null</code> permitted). * @param valueAxisLabel a label for the value axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param timeline the timeline. * @param legend a flag specifying whether or not a legend is required. * * @return a high-low-open-close chart. */ public static JFreeChart createHighLowChart(String title, String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset, Timeline timeline, boolean legend) { DateAxis timeAxis = new DateAxis(timeAxisLabel); timeAxis.setTimeline(timeline); NumberAxis valueAxis = new NumberAxis(valueAxisLabel); HighLowRenderer renderer = new HighLowRenderer(); renderer.setToolTipGenerator(new HighLowItemLabelGenerator()); XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
/** * Creates and returns a default instance of a high-low-open-close chart * with a special timeline. This timeline can be a * {@link org.jfree.chart.axis.SegmentedTimeline} such as the Monday * through Friday timeline that will remove Saturdays and Sundays from * the axis. * * @param title the chart title (<code>null</code> permitted). * @param timeAxisLabel a label for the time axis (<code>null</code> * permitted). * @param valueAxisLabel a label for the value axis (<code>null</code> * permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param timeline the timeline. * @param legend a flag specifying whether or not a legend is required. * * @return A high-low-open-close chart. */ public static JFreeChart createHighLowChart(String title, String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset, Timeline timeline, boolean legend) { DateAxis timeAxis = new DateAxis(timeAxisLabel); timeAxis.setTimeline(timeline); NumberAxis valueAxis = new NumberAxis(valueAxisLabel); HighLowRenderer renderer = new HighLowRenderer(); renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator()); XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
/** * Creates and returns a default instance of a high-low-open-close chart * with a special timeline. This timeline can be a * {@link org.jfree.chart.axis.SegmentedTimeline} such as the Monday * through Friday timeline that will remove Saturdays and Sundays from * the axis. * * @param title the chart title (<code>null</code> permitted). * @param timeAxisLabel a label for the time axis (<code>null</code> * permitted). * @param valueAxisLabel a label for the value axis (<code>null</code> * permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param timeline the timeline. * @param legend a flag specifying whether or not a legend is required. * * @return A high-low-open-close chart. */ public static JFreeChart createHighLowChart(String title, String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset, Timeline timeline, boolean legend) { DateAxis timeAxis = new DateAxis(timeAxisLabel); timeAxis.setTimeline(timeline); NumberAxis valueAxis = new NumberAxis(valueAxisLabel); HighLowRenderer renderer = new HighLowRenderer(); renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator()); XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Notification when the scrollbar's model changes. * * @param event */ public void adjustmentValueChanged(AdjustmentEvent event) { if (mUpdating) { return; } mUpdating = true; double start = getValue() / mRatio + mDataRangeMin; double end = start + mViewLength; if (end > start) { Timeline tl = ((DateAxis) mDomainAxis).getTimeline(); start = tl.toMillisecond((long) start); end = tl.toMillisecond((long) end); mDomainAxis.setRange(start, end); //System.out.println(String.format("start=%f end=%f", start, end)); } mUpdating = false; }
private void updateAxis() { if (mUpdating) { return; } mUpdating = true; double viewMin = 0; double viewMax = 0; Range dataRange = mPlot.getDataRange(mDomainAxis); if (dataRange != null) { mDataRangeMin = dataRange.getLowerBound(); mDataRangeMax = dataRange.getUpperBound(); if (mFirstTime) { mDomainAxis.setAutoRange(false); mDomainAxis.setRange(mDataRangeMin, mDataRangeMin + mPageSizeMillis); // 30s } viewMin = mDomainAxis.getLowerBound(); viewMax = mDomainAxis.getUpperBound(); Timeline tl = mDomainAxis.getTimeline(); mDataRangeMin = tl.toTimelineValue((long) mDataRangeMin); mDataRangeMax = tl.toTimelineValue((long) mDataRangeMax); viewMin = tl.toTimelineValue((long) viewMin); viewMax = tl.toTimelineValue((long) viewMax); mViewLength = viewMax - viewMin; mRatio = STEPS / (mDataRangeMax - mDataRangeMin); if (mFirstTime) { // Must do this to support page scrolling when // clicking in the scrollbar "gutter". Make the // blockIncrement somewhat smaller than the view size // so teh user sees the old value when page scrolling. int blockIncrement = (int) (mPageSizeMillis * 0.9 * STEPS / mViewLength); setBlockIncrement(blockIncrement); setUnitIncrement(blockIncrement / 20); mFirstTime = false; setVisible(true); } } else { mDataRangeMin = 0; mDataRangeMax = 0; mViewLength = 0; mRatio = 1; } int newMin = 0; int newMax = STEPS; int newExtent = (int) (mViewLength * mRatio); int newValue = (int) ((viewMin - mDataRangeMin) * mRatio); setValues(newValue, newExtent, newMin, newMax); mUpdating = false; }
/** * Getter for property timeline. * @return Value of property timeline. */ public Timeline getTimeline() { return this.timeline; }
/** * Setter for property timeline. * @param timeline New value of property timeline. */ public void setTimeline(Timeline timeline) { this.timeline = timeline; }