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

Message ListMessage List     Post MessagePost Message

  semi-circle in finance chart
Posted by chang on Sep-11-2014 17:04
Attachments:
Hi Peter,

How do I draw semi circles at the bottom of the main chart as shown in my picture? Do I addLineIndicator? Any suggestions? There isn't any example that shows this. Thanks.

Chang
cycle brackets example-ULTA.jpg

  Re: semi-circle in finance chart
Posted by Peter Kwan on Sep-12-2014 04:45
Hi chang,

You may consider to use DrawArea.arc to draw the semi-circles. In brief, it is like (in
Java/C#):


//save the return value from addMainChart, so we can use it layer
XYChart myMainChart = myFinanceChart.addMainChart(.........);

.... create chart and add all other indicators as usual .....


//layout all the charts, so we can know the axis scale
myFinanceChart.layout();

DrawArea d = myMainChart.makeChart3();

int startIndex = 60;
int endIndex = 90;

int centerX = myMainChart.getXCoor((startIndex + endIndex ) / 2.0 - extraPoints);
int radius = myMainChart.getXCoor((endIndex - startIndex) / 2.0);

d.arc(centerX, myMainChart.getPlotArea().getBottomY(), radius, radius, -90, 90,
0x000000);


The above draws one semi-circle. You can modify it to using a loop to draw multiple
semi-circles.

Hope this can help.

Regards
Peter Kwan

  Re: semi-circle in finance chart
Posted by Chang on Sep-15-2014 19:24
Hi Peter,

I tried using those values you provided as tests. The diameter of the semi circle should be 30 bars but on drawing it's not; it's more than 30 bars and it seems like this number changes as I zoom in and out of the chart. I think its a problem with the getXCoor. Is there something else I should call first before calling getXCoor? Shouldn't getXCoor give me the pixels automatically and according to the resolution of the zoom? Thanks.

  Re: semi-circle in finance chart
Posted by Peter Kwan on Sep-16-2014 03:13
Hi Chang,

The only requirement to call getXCoor is to layout the charts first. The code should first
create the chart as usual, and enter all the data and configuration into the chart. The chart
needs these information to determine the axis scale. The it needs to layout the chart:

//layout all the charts, so we can know the axis scale
myFinanceChart.layout();

After that, it can obtain the draw area using "DrawArea d = myMainChart.makeChart3();"
and use getXCoor to get the pixel coordinates.

The code I provide assumes you are using the FinanceChart or a chart with a label based x-
axis, which has the property that 30 units mean 30 bars. The code should draw circles with
diameter equals to 30 x-axis units. If you zoom in, 30 x-axis units should become wider if
measured in pixel units.

If you can inform me which programming language you are using, I can provide a simple
example for you. You can also provide an example to me to help me reproduce the issue you
encountered.

Regards
Peter Kwan

  Re: semi-circle in finance chart
Posted by Chang on Sep-16-2014 13:26
Hi Peter

I am using the finance2 C# example. I am able to get the semi circle to start on 4/9/2002 but it kept ending at a later date than 4/10/2002. The centerX and radius are obviously the culprit. What am I doing wrong here? Modified it to remove the indicators and added the arc code segment below (x-axis is populated by CTime values of the DateTime equivalent) :

            c.layout();
            int axisOffset = xyc.yAxis2().getX();

            DrawArea da = xyc.makeChart3();

            DateTime startdt = DateTime.ParseExact("20020904", "yyyyMMdd", null);
            DateTime enddt = DateTime.ParseExact("20021004", "yyyyMMdd", null);

            double xx = Chart.CTime(startdt);
            int startIndex=-1;
            for (int i = 0; i < timeStamps.Length; i++)
                if (timeStamps[i] == xx)
                {
                    startIndex = i;
                    break;
                }
            double yy = Chart.CTime(enddt);
            int endIndex = -1;
            for (int i = 0; i < timeStamps.Length; i++)
                if (timeStamps[i] == yy)
                {
                    endIndex = i;
                    break;
                }

            int centerX = xyc.getXCoor((startIndex + endIndex ) / 2.0) + axisOffset;
            int radius = xyc.getXCoor((endIndex - startIndex) / 2.0);

            da.arc(centerX, xyc.getPlotArea().getBottomY(), radius, radius, -90, 90,
            0x000000);

  Re: semi-circle in finance chart
Posted by Chang on Sep-16-2014 13:28
Fyi...extraPoints for setData is set to zero 0. That's why you don't see that in the centerX calculation.

  Re: semi-circle in finance chart
Posted by Peter Kwan on Sep-17-2014 02:26
Hi Chang,

Sorry for this problem. After thinking more carefully, I found that the code for the radius is
not correct. It should be:

centerX = xyc.getXCoor((startIndex + endIndex ) / 2.0);
radius = xyc.getXCoor((endIndex - startIndex) / 2.0) - xyc.getXCoor(0);

The axisOffset is not necessary.

Hope this can help.

Regards
Peter Kwan