Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Get Image from Chart fails
 Post subject: Get Image from Chart fails Post rating: 0   Post Posted: Wed 07 Jan, 2015, 10:27 
User avatar

User rating: 0
Joined: Tue 06 Jan, 2015, 14:49
Posts: 5
Location: GermanyGermany
Hi everyone,

i'am a newbie in programming with JForex-API and i try to get a snapshot from a chart, so my strategy can send an email with this snapshot/image. But when i try to get the image from the chart i get the error "Width (0) and height (0) cannot be <= 0". What i'am doing wrong? Can you help me pls?

Here is my simple Strategy which tries to save the chart-snapshot to a file on my local disc (for testing) and after this the error in my eclipseconsole:

import java.awt.Dimension;
import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;

import com.dukascopy.api.*;
import com.dukascopy.api.util.*;
import com.dukascopy.api.feed.IFeedDescriptor;
import com.dukascopy.api.feed.util.*;

public class MyStrategy implements IStrategy {

    private IChart chart;
    private IContext context;
    private IConsole console;
   
    @Override
    public void onStart(IContext context) throws JFException { 
        this.context = context;
        this.console = context.getConsole();       
       
       
        IFeedDescriptor feedDescriptor = new TimePeriodAggregationFeedDescriptor(Instrument.EURUSD, Period.TEN_SECS, OfferSide.BID);
        chart = context.openChart(feedDescriptor);
       
        System.out.println("Chart's feed: " + chart.getFeedDescriptor()); //will print all feed's parameters
        System.out.println("Chart's instrument: " + chart.getFeedDescriptor().getInstrument()); //retrieve a specific feed parameter
       
        //wait until the feed gets loaded
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e1) {
            e1.printStackTrace(console.getErr());
        }
       
        System.out.println("Chart drawable coordinates: min(" + DateUtils.format(chart.getMinTime()) + "," + chart.getMinPrice() +
              "); max(" + DateUtils.format(chart.getMaxTime()) + "," + chart.getMaxPrice() + ")");
           
       
        try {
            File file = new File(context.getFilesDir().getPath() + File.separator + "ChartImage.png");
            ImageIO.write(chart.getImage(), "png", file);
            print("chart image saved in: " + file.getAbsolutePath());
        } catch (Exception e) {
            e.printStackTrace(console.getErr());
        }
       
    }
   
    @Override
    public void onStop() throws JFException {
        context.closeChart(chart);
    }
   
    private void print(Object o){
        console.getOut().println(o);
    }
   
    private void print(String message, Object... args){
        print(String.format(message,args));
    }

    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {}

    @Override
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}

    @Override
    public void onMessage(IMessage message) throws JFException {}

    @Override
    public void onAccount(IAccount account) throws JFException {}
}




2015-01-07 10:26:34.315 INFO  Main - Verbindungsaufbau zum Dukascopyserver...
2015-01-07 10:26:35.104 INFO  AuthorizationClient - Selecting the best server...
2015-01-07 10:26:36.610 INFO  AuthorizationClient - retry count = 1, properties request time = 2015-01-07 10:26:36
2015-01-07 10:26:37.013 INFO  AuthorizationClient - retry count = 1, properties response time = 2015-01-07 10:26:37
2015-01-07 10:26:37.064 INFO  ClientProtocolHandler - TcpNoDelay=false
2015-01-07 10:26:37.447 INFO  ClientConnector - Primary connect successfull, primarySession is [MinaIoSessionWrapper [session=(SOCKET, R: d-ja-gva-91-142.dukascopy.com/194.8.15.142:10443, L: /192.168.3.148:51533, S: d-ja-gva-91-142.dukascopy.com/194.8.15.142:10443)]], address is [d-ja-gva-91-142.dukascopy.com/194.8.15.142:10443]
2015-01-07 10:26:37.540 WARN  WLabelData - White Label Image is not received
2015-01-07 10:26:38.133 INFO  GreedClientAuthorizationProvider - !!!:Thread[ClientConnector,5,main]
2015-01-07 10:26:38.421 INFO  DCClientImpl - Connected
2015-01-07 10:26:38.541 INFO  Main - Subscribing instruments...
2015-01-07 10:26:38.544 INFO  Main - Instruments subscribed!
2015-01-07 10:26:39.189 INFO  ClientConnector - Child session opened for [d-ja-gva-91-142.dukascopy.com/194.8.15.142:10443]
Chart's feed: FeedDescriptor [dataType=TIME_PERIOD_AGGREGATION, instrument=EUR/USD, offerSide=Bid, period=10 Secs, filter=NO_FILTER, ]
Chart's instrument: EUR/USD
Chart drawable coordinates: min(1969-12-31 23:59:59:999,1.0); max(1969-12-31 23:59:59:999,2.0)
java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0
   at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source)
   at java.awt.image.BufferedImage.<init>(Unknown Source)
   at com.dukascopy.charts.utils.SnapshotHelper.writeToImage(SnapshotHelper.java:59)
   at com.dukascopy.charts.chartbuilder.ChartController.getWorkspaceImage(ChartController.java:570)
   at com.dukascopy.charts.chartbuilder.IChartWrapper.getImage(IChartWrapper.java:891)
   at com.dukascopy.charts.wrapper.DelegatableChartWrapper.getImage(DelegatableChartWrapper.java:530)
   at PerformForexSignals.kannweg.onStart(kannweg.java:45)
   at com.dukascopy.api.impl.execution.TaskStart.call(TaskStart.java:27)
   at com.dukascopy.api.impl.execution.TaskStart.call(TaskStart.java:13)
   at com.dukascopy.api.impl.connect.JFRunnableProcessor.onStart(JFRunnableProcessor.java:127)
   at com.dukascopy.api.impl.connect.JForexTaskManager$1.call(JForexTaskManager.java:663)
   at com.dukascopy.api.impl.connect.JForexTaskManager$1.call(JForexTaskManager.java:630)
   at com.dukascopy.api.impl.execution.TaskCustom.call(TaskCustom.java:34)
   at java.util.concurrent.FutureTask.run(Unknown Source)
   at com.dukascopy.api.impl.execution.ScienceThreadPoolExecutor$Worker.runTask(ScienceThreadPoolExecutor.java:904)
   at com.dukascopy.api.impl.execution.ScienceThreadPoolExecutor$Worker.run(ScienceThreadPoolExecutor.java:926)
   at java.lang.Thread.run(Unknown Source)



 
 Post subject: Re: Get Image from Chart fails Post rating: 0   Post Posted: Thu 08 Jan, 2015, 15:45 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Hi,

Maybe a bug in the getImage() function?

You have to verify.

Try something like this:
...
    File file = new File(context.getFilesDir().getPath() + File.separator + "ChartImage.png");
    BufferedImage image = chart.getImage();
    // check for the width/height:
    print("height: " + image.getHeight());
    print("width: " + image.getWidth());

If these are also 0, then I think it is a bug, so report in the Bug sections of the forum.


 
 Post subject: Re: Get Image from Chart fails Post rating: 0   Post Posted: Fri 09 Jan, 2015, 10:04 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi!
We could not reproduce the problem you described (JForex Platform 2.42.5). What version of JForex Platform did you use? Does the problem still persist?


 

Jump to:  

cron
  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com