/// <summary> /// Create the chart using the data. /// </summary> private JFreeChart createChart(DefaultTableXYDataset dataset) { string xlabel = "Surface Area (ACRE)"; if (__type.Equals("Seepage")) { xlabel = "Seepage (AF/M)"; } JFreeChart chart = ChartFactory.createXYLineChart("Reservoir Content/" + __type + " Curve", xlabel, "Content (ACFT)", dataset, PlotOrientation.VERTICAL, false, true, false); chart.addSubtitle(new TextTitle(__res.getID() + " (" + __res.getName() + ")")); //TextTitle source = new TextTitle("Source: rgtTW.res"); //source.setFont(new Font("SansSerif", Font.PLAIN, 10)); //source.setPosition(RectangleEdge.BOTTOM); //source.setHorizontalAlignment(HorizontalAlignment.RIGHT); //chart.addSubtitle(source); chart.setBackgroundPaint(Color.WHITE); XYPlot plot = (XYPlot)chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return(chart); }
public static void Main(string[] args) { // Getting the time series TimeSeries series = CsvTradesLoader.loadBitstampSeries(); // Building the trading strategy Strategy strategy = MovingMomentumStrategy.buildStrategy(series); /// <summary> /// Building chart datasets /// </summary> TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(buildChartTimeSeries(series, new ClosePriceIndicator(series), "Bitstamp Bitcoin (BTC)")); /// <summary> /// Creating the chart /// </summary> JFreeChart chart = ChartFactory.createTimeSeriesChart("Bitstamp BTC", "Date", "Price", dataset, true, true, false); // generate URLs? - generate tooltips? - create legend? - data - y-axis label - x-axis label - title XYPlot plot = (XYPlot)chart.Plot; DateAxis axis = (DateAxis)plot.DomainAxis; axis.DateFormatOverride = new SimpleDateFormat("MM-dd HH:mm"); /// <summary> /// Running the strategy and adding the buy and sell signals to plot /// </summary> addBuySellSignals(series, strategy, plot); /// <summary> /// Displaying the chart /// </summary> displayChart(chart); }
public static void Main(string[] args) { /// <summary> /// Getting time series /// </summary> TimeSeries series = CsvTradesLoader.loadBitstampSeries().subseries(0, Period.hours(6)); /// <summary> /// Creating the OHLC dataset /// </summary> OHLCDataset ohlcDataset = createOHLCDataset(series); /// <summary> /// Creating the additional dataset /// </summary> TimeSeriesCollection xyDataset = createAdditionalDataset(series); /// <summary> /// Creating the chart /// </summary> JFreeChart chart = ChartFactory.createCandlestickChart("Bitstamp BTC price", "Time", "USD", ohlcDataset, true); // Candlestick rendering CandlestickRenderer renderer = new CandlestickRenderer(); renderer.AutoWidthMethod = CandlestickRenderer.WIDTHMETHOD_SMALLEST; XYPlot plot = chart.XYPlot; plot.Renderer = renderer; // Additional dataset int index = 1; plot.setDataset(index, xyDataset); plot.mapDatasetToRangeAxis(index, 0); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false); renderer2.setSeriesPaint(index, Color.blue); plot.setRenderer(index, renderer2); // Misc plot.RangeGridlinePaint = Color.lightGray; plot.BackgroundPaint = Color.white; NumberAxis numberAxis = (NumberAxis)plot.RangeAxis; numberAxis.AutoRangeIncludesZero = false; plot.DatasetRenderingOrder = DatasetRenderingOrder.FORWARD; /// <summary> /// Displaying the chart /// </summary> displayChart(chart); }
/// <summary> /// Displays a chart in a frame. </summary> /// <param name="chart"> the chart to be displayed </param> private static void displayChart(JFreeChart chart) { // Chart panel ChartPanel panel = new ChartPanel(chart); panel.FillZoomRectangle = true; panel.MouseWheelEnabled = true; panel.PreferredSize = new Dimension(1024, 400); // Application frame ApplicationFrame frame = new ApplicationFrame("Ta4j example - Buy and sell signals to chart"); frame.ContentPane = panel; frame.pack(); RefineryUtilities.centerFrameOnScreen(frame); frame.Visible = true; }
/// <summary> /// Display a graph of reservoir content versus area or content versus seepage. </summary> /// <param name="dataset"> The dataset including the reservoir. </param> /// <param name="res"> StateMod_Reservoir with data to graph. </param> /// <param name="type"> "Area" or "Seepage", indicating the data to graph. </param> /// <param name="editable"> Indicate whether the data are editable or not (currently /// ignored and treated as not editable through the graph). </param> public StateMod_Reservoir_AreaCap_Graph_JFrame(StateMod_DataSet dataset, StateMod_Reservoir res, string type, bool editable) { StateMod_GUIUtil.setTitle(this, dataset, res.getName() + " - Reservoir Content/" + type + " Curve", null); JGUIUtil.setIcon(this, JGUIUtil.getIconImage()); __res = res; __type = type; DefaultTableXYDataset graph_dataset = createDataset(); JFreeChart chart = createChart(graph_dataset); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(500, 500)); getContentPane().add("Center", chartPanel); pack(); JGUIUtil.center(this); setVisible(true); }
public static BufferedImage getJFreeChart() { BufferedImage bufferedImage = null; try { //string reports_dir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "reports"); //string fileName = System.IO.Path.Combine(reports_dir, "AreaChart.jpg"); //bufferedImage = ImageIO.read(new File(fileName)); DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("Java", 43.2); dataset.setValue("Visual Basic", 10.0); dataset.setValue("C/C++", 17.5); dataset.setValue("PHP", 32.5); dataset.setValue("Perl", 1.0); JFreeChart chart = ChartFactory.createPieChart3D( "Pie Chart 3D Demo 1", dataset, true, true, false ); PiePlot3D plot = (PiePlot3D)chart.getPlot(); plot.setStartAngle(290); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); plot.setNoDataMessage("No data to display"); /* */ bufferedImage = chart.createBufferedImage(515, 350); } catch (Exception ex) { throw ex; } return(bufferedImage); }
/// <summary> /// Create the panel to hold the chart. /// </summary> public virtual JPanel createDemoPanel() { JFreeChart chart = createChart(createDataset()); return(new ChartPanel(chart)); }
override public void customize(JFreeChart chart, ChartComponent chartComponent) { chart.getPlot().setOutlineVisible(true); chart.getPlot().setOutlinePaint(new Color(0, 0, 255)); chart.getPlot().setOutlineStroke(new BasicStroke(1f)); }