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

Message ListMessage List     Post MessagePost Message

  Get Y-Axis minimum and Maximum
Posted by Pavan on Dec-23-2016 12:56
Hi All,

How to get the Y-Axis minimum and maximum values when WinChartViewer is used?
I need to figure out what is the current minimum and maximum value that is being shown to user when user zoom in/ zoom out.

Regards,
Pavan

  Re: Get Y-Axis minimum and Maximum
Posted by Peter Kwan on Dec-23-2016 13:21
Hi Pavan,

If the chart has already been shown to the user, the maximum and minimum can be obtained using Axis.getMaxValue and Axis.getMinValue. For example:

double maxValue = c.yAxis().getMaxValue();
double minValue = c.yAxis().getMinValue();

Hope this can help.

Regards
Peter Kwan

  Re: Get Y-Axis minimum and Maximum
Posted by Pavan on Dec-23-2016 14:28
Thanks Peter for immediate response.

But this is giving me different values like what i set during chart creation/may be when presented.

But Y-Axis gets changed when user zooms in, now axis may be changed like this
minimum 32 and maximum 62. This is what Chart shows when presented to User. These Changed values I want to get before it is presented to user  to process some logic.

Thanks,
Pavan

  Re: Get Y-Axis minimum and Maximum
Posted by Pavan on Dec-23-2016 19:04
Hi Peter,

Some how I am able to figure out the values that I need while debugging. But I am not sure how can we get them using any available API.

(((ChartDirector.XYChart)(yAxis.f)).a.m).Items[2].m
(((ChartDirector.XYChart)(yAxis.f)).a.m).Items[2].n

Thanks in Advance,
Pavan

  Re: Get Y-Axis minimum and Maximum
Posted by Peter Kwan on Dec-23-2016 23:47
Hi Pavan,

If the chart has not yet been drawn, the method to determine the axis scale depends on how the axis scale is determined:

(a) If the axis scale is automatically determined by ChartDirector based on the data values, your code would need to add all the data to the chart first, then call XYChart.layoutAxes or BaseChart.layout to inform ChartDirector that all the data have already been added so that it can compute the axis scale. After that, your code can use Axis.getMinValue and Axis.getMaxValue to obtain the axis scale.

(b) If the chart is zoomable in the y-direction so that the axis scale is determined by user actions, you can use WinChartViewer.getValueAtViewPort to determine the user selection (assuming C# Windows Forms). For example:

double maxValue = viewer.getValueAtViewPort("y", viewer.ViewPortTop);
double minValue = viewer.getValueAtViewPort("y", viewer.ViewPortTop + viewer.ViewPortHeight);

(c) If the y-axis scale is determined by your code (such as calling Axis.setLinearScale), your code already knows the axis scale. Your just need to design the code to keep track of the min/max values.

Regards
Peter Kwan

  Re: Get Y-Axis minimum and Maximum
Posted by Pavan on Dec-26-2016 14:23
Hi Peter,

I tried getValueatViewport(), it gives the values that are plotted on Chart i.e. maximum and minimum value what user can see on chart.

But my requirement is to get minimum and maximum of Y-axis where these points are plotted. These values are available as earlier mentioned in Axis as below.

Axis.m
and
Axis.n

Please help me how to get these properties using any API.

Thanks,
Pavan

  Re: Get Y-Axis minimum and Maximum
Posted by Peter Kwan on Dec-26-2016 22:22
Hi Pavan,

Do you mean the pixel coordinates of the y-axis end points? In most chart configuration, the y-axis end points are just the plot area top and bottom, which can be obtained as:

int topY = c.getPlotArea().getTopY();
int bottomY = c.getPlotArea().getBottomY();

In some y-axis configuration in which there are axis margins, you can adjust the above coordinates by the margin you configured, or you can obtain the pixel coordinates of the min and max values using XYChart.getYCoor. For example:

// remember to layoutAxes first
int topY = c.getYCoor(c.yAxis().getMaxValue());
int bottomY = c.getYCoor(c.yAxis().getMinValue());

Hope this can help.

Regards
Peter Kwan