ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  draw rectangle in finance chart
Posted by chang on Dec-17-2012 18:39
Attachments:
Hi Peter

As shown in the example attached, how can I mouse click and drag to draw a rectangle in the finance chart? I've looked through the examples that came with chartdirector and thought scatter layer was the way to go but it requires my x-axis input data to be double[] but it's a datetime-based x-axis. Is there a way around this or is there a better solution? I am coding in C#. Please advise. Thanks!
chart rectangle.jpg

  Re: draw rectangle in finance chart
Posted by Peter Kwan on Dec-18-2012 01:20
Attachments:
Hi chang,

The examples are just specific examples of using ChartDirector. They do not mean you must follow the examples exactly. In particular, ChartDirector does not require your x input to be double[]. It can be date/time as well. You can just modify the code to use date/time as x-data.

For a standard Financial Chart like a candlestick chart, the x-axis should more accurate be described as trading sessions. It is because financial charts only plot trading days, which excludes weekends, national holidays, certain natural disasters, etc (eg. a recent storm has caused the trading to stop in New York Stock Exchange). Because the trading "dates" are rather random, they are not suitable to be used as an axis scale. In a FinanceChart, the timeStamps are just used as "names" for human reading.

I have attached a C# Windows Forms example for your reference. You may take note of the "drawChart" subroutine. Basically, it first determines the trading sessions to be plotted based on the view port. Then it obtains the required data and plots the chart.

Hope this can help.

Regards
Peter Kwan
financezoom.zip
financezoom.zip

6.00 Kb

  Re: draw rectangle in finance chart
Posted by Chang on Dec-19-2012 18:56
Hi Peter

You didn't answer my question. I need to draw a colored semi transparent rectangle as shown in the pic...that's the more important thing. How do I do that in the finance chart? Please help. Thanks.

  Re: draw rectangle in finance chart
Posted by Peter Kwan on Dec-20-2012 01:15
Hi Chang,

Do you mean you want to interactively draw a rectangle on top of the chart image like using an interactive graphics editor (such as Windows Paint or Photoshop)? Do you also need to interactively edit the rectangle (move the rectangle, resize the rectangle, delete the rectangle, etc)?

ChartDirector can draw a transparent rectangle, but ChartDirector currently does not have built-in interactive graphics editor function. Also, for interactive graphics editing, using ChartDirector may not be necessary. (For example, if you edit a photograph, you may not want to use the system that creates the image - which is the digital camara. Instead, you may use another system on your computer to modify the image.)

In the simplest case, to interactively draw a rectangle, first you would need to obtain the user inputs. You can do this by handle the mouse events. After you obtain the user inputs, you may just draw the semi-transparent rectangle on top of the chart image. The exact details depend on your GUI framework. For a web application, you may put a DIV block with a semi-transparent background color over the chart image. For a Windows Forms application, you may override the Control.Paint event to include the rectangle.

If you would like ChartDirector to draw the rectangle, you may use BaseChart.addText, like:

//assuming the top-left and bottom-right points of the rectangle is (x1, y1) and (x2, y2)
ChartDirector.TextBox t = c.addText(x1, y1, "");
t.setSize(x2 - x1 + 1, y2 - y1 + 1);
t.setBackground(0x80ffff00);

Regards
Peter Kwan







Chang wrote:

Hi Peter

You didn't answer my question. I need to draw a colored semi transparent rectangle as shown in the pic...that's the more important thing. How do I do that in the finance chart? Please help. Thanks.

  Re: draw rectangle in finance chart
Posted by Chang on Dec-20-2012 17:58
Hi Peter

yes I wanted to interactively draw the rectangle with a mouse click and drag action. Initially I was looking at drawing 2 parallel horizontal lines and creating a interline layer in between but I think your method looks simpler and better. I shall give it a shot. Thanks for the advise.