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

Message ListMessage List     Post MessagePost Message

  control right side marker
Posted by reddy on Nov-26-2021 21:05
Attachments:
Hello Peter,

Is it possible to add a pointer/marker on the price scale similar to this?
rightmarker.png

  Re: control right side marker
Posted by Peter Kwan on Nov-29-2021 17:53
Attachments:
Hi Reddy,

I am not sure which programming language edition of ChartDirector you are using, or whether you are writing a web or desktop application.

In general, you can combine several featues demonstrated in the ChartDirector sample code to achieve what you need.

First, the Axis.addMark method can be used to put a mark on the y-axis, as demonstrated in the Marks and Zones sample code. (The following the .NET version of the sample code. You may refer to the documentation that comes with your ChartDirector for the sample code in your programming language.)

https://www.advsofteng.com/doc/cdnet.htm#markzone.htm

The mark label is a TextBox object. You can configures is font, background color, border color, etc, to fit you needs. The chart attached below is example that uses a non-transparent background color.

For the main price data, you can add a mark at the last closing price or whichever price you want to use. The y-axis to use is the yAxis of the main price chart (which is an XYChart object) inside the FinanceChart.

You can do the same to other indicators. To add a mark, you need to specify the y-value to use. If the indicator is computed by ChartDirector, the "Finance Chart Track Line" sample code demonstrates how to obtain the indicator values computer by ChartDirector.

https://www.advsofteng.com/doc/cdnet.htm#trackfinance.htm

The above sample code obtains the indicator value at the mouse position. Instead of using the mouse position, you can use the right most coordinate of your chart. This will obtain the last data value.

For your information, the following is the code I use to create the attached chart (in C# on a Windows Forms application):


... create finance chart as usual ...

// Here is the main price chart
XYChart p = m.addMainChart(.....);

// The moving averages
Layer movAvg = c.addSimpleMovingAvg(10, 0x663300);
Layer movAvg2 = c.addSimpleMovingAvg(20, 0x9900ff);

... after the finance chart confguration is completed ...

// Layout the chart first
c.layout();

// Add mark for the last closing price
double lastClosePrice = closeData[closeData.Length - 1];
Mark m = p.yAxis().addMark(lastClosePrice, -1, "" + c.formatValue(lastClosePrice, "{value|P3}"), "Arial Bold", 8);
m.setBackground(0xcc0000);
m.setFontColor(0xffffff);

// Add marks for the indicators computed by ChartDirector
int xPos = movAvg.getXIndexOf(movAvg.getNearestXValue(c.getWidth()));
foreach (Layer layer in new Layer[] { movAvg, movAvg2 })
{
double yValue = layer.getDataSet(0).getValue(xPos);
m = p.yAxis().addMark(yValue, -1, c.formatValue(yValue, "{value|P3}"), "Arial Bold", 8);
m.setBackground(layer.getDataSet(0).getDataColor());
m.setFontColor(0xffffff);
}


Regards
Peter Kwan
test.png