Nevron Forum

Bars crossing over axis bounds when X Axis added.

https://www.nevron.com/Forum/Topic2448.aspx

By David Huxtable - Monday, June 29, 2009

Good Morning,

I have set my chart's bounds mode to fit yet when I add an x axis title I noticed the bars are bigger, yet the axes don't grow in size with the bars. I haven't added any extra information besides the table so th ebars shouldn't grow like such.

Is there a certain property I need to set to a certain value to stop this?

When comparing whatI have done with the examples, I cannot see a difference but there is a good possibility I have missed something.

Any help would be greatly appreciated.

Thank you in advance for your time,

David
By Blagovest Milanov 1 - Monday, June 29, 2009

Hi David,

Can you post the code you're testing with along with an image showing the problem - I don't think I understand the question properly...

Best regards,

Bob

By David Huxtable - Monday, June 29, 2009

Thank you for your quick reply Bob,

Sorry I have attached the screenshots as so I can explain my situation a little clearer.

Basically the bar on the very left is sitting over the Y axis and Y axis labels and the bar on the far right is also outside its bounds.

However, when I remove the x axis label, this is no longer so.

My axis label code is simply:

xAxisLabel.Title.Angle = new NScaleLabelAngle(0);
xAxisLabel.Title.RulerAlignment = HorzAlign.Center;
xAxisLabel.Title.ContentAlignment = System.Drawing.ContentAlignment.MiddleCenter;
chart.Charts[0].Axis(StandardAxis.PrimaryX).ScaleConfigurator = xAxisLabel;
xAxisLabel.Title.RulerOffset = new NLength(0, NRelativeUnit.ParentPercentage);
xAxisLabel.Title.TextStyle.FontStyle.Style = System.Drawing.FontStyle.Bold;
xAxisLabel.LabelGenerationMode = LabelGenerationMode.SingleLevel;
xAxisLabel.RoundToTickMax = false;
xAxisLabel.RoundToTickMin = false;
xAxisLabel.AutoLabels = false;

I am not sure what I could have done wrong.

Thank you once again for your help Bob, I hope I haven't given you too great a headache,

David

By Blagovest Milanov 1 - Tuesday, June 30, 2009

Hi David,

 

No worries

 

The problem is that you're applying a linear scale to the X axis. I was able to reproduce the same behavior with the following code:

 

NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0];

NBarSeries bar = new NBarSeries();

bar.Values.AddRange(new double[] { 12, 15, 16 });

bar.InflateMargins = true;

chart.Series.Add(bar);

 

NLinearScaleConfigurator linearScale = new NLinearScaleConfigurator();

chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = linearScale;

Generally, the component is behaving according to specification as the ordinal scale (which is the default X axis for series that do not use X values - like XY scatters) will inflate the original range (0-2) to (-0.5, 2.5), which produces the bar that does not overwrite the axis.

 

The simplest way to fix this is to revise the code and change the place where you create a NLinearScaleConfigurator and use a NOrdinalScaleConfigurator instead - I'm not sure why you use it, but generally it is necessary when you want to have scale decoration based on a double arithmetic instead of integer (which is the case with ordinal scales). The other way around is to apply a range inflate to the configurator.

 

Hope this helps - let me know if the problem persists.

Best regards,
Bob

By David Huxtable - Tuesday, June 30, 2009

Thank you very much for your help, once again, Bob.

The NOrdinalScaleConfigurator worked a treat

I knew it must have been something I had done, just couldn't pick it because it wasn't happening on another chart but my values were integers, thus I when comparing the code between the two, all the property settings looked identical, I didn't think about the values the charts were outputting.

This is something I will never forget!

Thank you again Bob,

David
By John Burcher 1 - Thursday, July 9, 2009

Hi,

After using the code above it also fixed my issue, yay!

But how do I make the X Axis start at 1 (and not 0?

Thank you!
By Blagovest Milanov 1 - Thursday, July 9, 2009

Hi John,

 

You can override the label value formatter:

 

public class NCustomValueFormatter : NNumericValueFormatter

{

    public override string FormatValue(object obj)

    {

        double val = (double)obj;

        return base.FormatValue(val + 1);

    }

}

 

private void Form1_Load(object sender, EventArgs e)

{

    NChart chart = nChartControl1.Charts[0];

   

    NBarSeries bar = new NBarSeries();

    bar.Values.Add(10);

    bar.Values.Add(20);

    bar.Values.Add(30);

   

    chart.Series.Add(bar);

   

    NOrdinalScaleConfigurator scale = chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator as NOrdinalScaleConfigurator;

    scale.LabelValueFormatter = new NCustomValueFormatter();

}

Let me know if you meet any problems...

Best regards,
Bob