0
votes

I'm trying to draw a signal response on a chart and I need a logarithmic scale for X and Y. I defined two functions, one for X axis

private void Configure_Axis_X(bool Logaritmic, double Maximum, double Minimum, double Interval)
{
    CH_EQ_Chart.ChartAreas[0].AxisX.IsLogarithmic = Logaritmic;
    CH_EQ_Chart.ChartAreas[0].AxisX.Minimum = Minimum;
    CH_EQ_Chart.ChartAreas[0].AxisX.Maximum = Maximum;
    CH_EQ_Chart.ChartAreas[0].AxisX.Interval = Interval;
    CH_EQ_Chart.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Black;
    CH_EQ_Chart.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = Graph.ChartDashStyle.Dash;
}

and one for Y axis

private void Configure_Axis_Y(bool Logaritmic, double Maximum, double Minimum, double Interval)
{
    CH_EQ_Chart.ChartAreas[0].AxisY.IsLogarithmic = Logaritmic;
    CH_EQ_Chart.ChartAreas[0].AxisY.Minimum = Minimum;
    CH_EQ_Chart.ChartAreas[0].AxisY.Maximum = Maximum;
    CH_EQ_Chart.ChartAreas[0].AxisY.Interval = Interval;
    CH_EQ_Chart.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Black;
    CH_EQ_Chart.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = Graph.ChartDashStyle.Dash;
}

the response to draw is expressed in Decibel and I'd like to have logarithmic scale also for Y.

When I have the array with values, I get minimum and maxim value and I try to use the function above with

double Abs_Max = Math.Max(y.Max(), z.Max());
double Abs_Min = Math.Min(y.Min(), z.Min());
Configure_Axis_Y(true, Abs_Max + Abs_Max/10, Abs_Min + Abs_Min/10, 20);

but when I select islogaritmic = true a red cross appears instead the graph. If I set islogaritmic = false the picture appears right.

1

1 Answers

1
votes

The red cross is the chart's way of handling an exception during drawing. The most likely culprit when dealing with log scale is that one or more data points have zero or negative values. Check in the debugger what Abs_Min is when the method is called, as it's likely you're somehow getting zero or negative values in there.