Profile Picture

How to set a custom MajorTick?

Posted By Alexander Konjaew 13 Years Ago
Author
Message
Alexander Konjaew
Posted 13 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 6, Visits: 1

Hi.

In my chart where the y axis has a logarithmic scale I visualize errors and there is a section, too, which represents the critical region. The user is able to change and set this region by the combo box (see the picture).

My problem is, that I do not know how to set additional major ticks (in this example 0.336). The MajorTickMode is set to CustomSteps and it is ok. But I'm not able to add another ticks in this mode. Changing the MajorTickMode to CustomTicks clear all existing major ticks, and I can not add more than one

Do you have any idea?

 



Attachments
errorbar.JPG (65 views, 50.00 KB)
Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: 2 days ago @ 1:54 AM
Posts: 3,054, Visits: 4,009

Hi,

Looks like there is no attached image with your post. Can you please edit and add the screenshot.



Best Regards,
Nevron Support Team



Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: 2 days ago @ 1:54 AM
Posts: 3,054, Visits: 4,009

Hi Alexander,

You can add custom ticks / labels/ gridlines etc. by creating custom decorators that are later added to the scale definition - for example:

   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);

   NAxis yAxis = chart.Axis(StandardAxis.PrimaryY);
   NLogarithmicScaleConfigurator logScale = new NLogarithmicScaleConfigurator();
   logScale.TransformScale = false;
   yAxis.ScaleConfigurator = logScale;

   yAxis.UpdateScale();

   NCustomScaleDecorator decorator = new NCustomScaleDecorator();

   NScaleValueDecorationAnchor anchor = new NScaleValueDecorationAnchor(12);
   NScaleTick tick = new NScaleTick(anchor, ScaleTickShape.Line, new NLength(0), new NSizeL(1, 4), null, new NStrokeStyle(2, Color.Red));
   decorator.Decorations.Add(tick);

   ((NScaleLevel)yAxis.Scale.Levels[2]).Decorators.Add(decorator);

This code creates a custom tick at value [12]. Note that it is added to the decorators on scale level 2 - the levels on a regular axis are:

0 - inner ticks

1 - ruler

2 - outer ticks

3 - labels

4 - titles

Hope this helps - let us know if you meet any problems.



Best Regards,
Nevron Support Team



Alexander Konjaew
Posted 13 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 6, Visits: 1

It works! Thanks.

But now, to be honest, I understand nothing. Adding the decorator to level 2 (outer tick) doesn't set the tick on the y axis but directly between the numbers of the scale. And level 0 separates all the other ticks from the axis. Only the level 1 does what I want. Was I not looking for a tick but for a ruler? hmm..

How can I add corresponding value of this tick now?



Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: 2 days ago @ 1:54 AM
Posts: 3,054, Visits: 4,009

Hi Alexander,

The number of levels may vary - that is when you don't have inner ticks all levels will be shifted upward by one - same goes for the other levels. This makes it tricky to find the correct level so can you post the code you use to configure the axis?



Best Regards,
Nevron Support Team



Alexander Konjaew
Posted 13 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 6, Visits: 1

Hello,

this is my example:

public partial class Form1 : Form

{

private NScaleSectionStyle _SectionStyle;

private NumberFormatInfo _NumberFormatProvider;

public Form1()

{

InitializeComponent();

_NumberFormatProvider = new NumberFormatInfo();

_NumberFormatProvider.NumberDecimalSeparator = ".";

toolStripComboBox1.SelectedIndex = 0;

SetScaleConfigurator();

AddData();

}

private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e)

{

if (toolStripComboBox1.Items.Count > 0 && _SectionStyle != null)

{

NAxis yAxis = nChartControl1.Charts[0].Axis(StandardAxis.PrimaryY);

yAxis.ScaleConfigurator.Sections.Clear();

double value = Convert.ToDouble(toolStripComboBox1.Text, _NumberFormatProvider);

AddSection(value);

nChartControl1.Refresh();

NCustomScaleDecorator decorator = new NCustomScaleDecorator();

NScaleValueDecorationAnchor anchor = new NScaleValueDecorationAnchor(value);

NScaleTick tick = new NScaleTick(anchor, ScaleTickShape.Line, new NLength(0), new NSizeL(1, 4), null, new NStrokeStyle(1, Color.Red));

decorator.Decorations.Add(tick);

nChartControl1.Charts[0].Axis(StandardAxis.PrimaryY).UpdateScale();

((NScaleLevel)nChartControl1.Charts[0].Axis(StandardAxis.PrimaryY).Scale.Levels[1]).Decorators.Add(decorator);

}

}

private void AddData()

{

// add series

List<double> xValues = new List<double>() { 1, 2, 3, 4, 5 };

List<double> yValues = new List<double>() { 0.18, 0.25, 3, 4, 5 };

List<double> yLowerValues = new List<double>() { .1, .1, 1, 1, 1 };

List<double> yUpperValues = new List<double>() { .1, .1, 1, 1, 10 };

NErrorBarSeries errorBarSeries = (NErrorBarSeries)nChartControl1.Charts[0].Series.Add(SeriesType.ErrorBar);

// ... change some series settings 

// ...

// add section for critical region

AddSection(Convert.ToDouble(toolStripComboBox1.Text, _NumberFormatProvider));

}

private void AddSection(double value)

{

_SectionStyle = new NScaleSectionStyle();

_SectionStyle.Range = new NRange1DD(0, value);

_SectionStyle.SetShowAtWall(ChartWallType.Back, true);

_SectionStyle.RangeFillStyle = new NColorFillStyle(Color.MistyRose);

NStandardScaleConfigurator scaleConfigurator = (NStandardScaleConfigurator)nChartControl1.Charts[0].Axis(StandardAxis.PrimaryY).ScaleConfigurator;

scaleConfigurator.Sections.Add(_SectionStyle);

}

private void SetScaleConfigurator()

{

// X axis

NOrdinalScaleConfigurator scaleOrdinal = new NOrdinalScaleConfigurator();

scaleOrdinal.SetPredefinedScaleStyle(PredefinedScaleStyle.Standard);

scaleOrdinal.MinorTickCount = 4;

scaleOrdinal.MinTickDistance = new NLength(25);

scaleOrdinal.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true);

scaleOrdinal.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, true);

scaleOrdinal.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot;

scaleOrdinal.Labels.Clear();

scaleOrdinal.AutoLabels = false;

scaleOrdinal.MajorTickMode = MajorTickMode.CustomSteps;

scaleOrdinal.LabelFitModes = new LabelFitMode[] { LabelFitMode.Stagger2, LabelFitMode.AutoScale };

scaleOrdinal.LabelStyle.Angle = new NScaleLabelAngle((float)90);

nChartControl1.Charts[0].Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleOrdinal;

// Y axis

NLogarithmicScaleConfigurator scaleLogarithmic = new NLogarithmicScaleConfigurator();

scaleLogarithmic.SetPredefinedScaleStyle(PredefinedScaleStyle.Scientific);

scaleLogarithmic.MinorGridStyle.LineStyle.Pattern = LinePattern.Dot;

scaleLogarithmic.MinorTickCount = 4;

//scaleLogarithmic.TransformScale = false;

scaleLogarithmic.MajorTickMode = MajorTickMode.CustomSteps;

scaleLogarithmic.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true);

scaleLogarithmic.MinorGridStyle.SetShowAtWall(ChartWallType.Back, true);

nChartControl1.Charts[0].Axis(StandardAxis.PrimaryY).ScaleConfigurator = scaleLogarithmic;

nChartControl1.Charts[0].Axis(StandardAxis.PrimaryY).View = new NRangeAxisView(new NRange1DD(0.01, 100), true, true);

}

}

I have found out that setting TransformScale = true considerably make my application slow and the window judders on resizing.



Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: 2 days ago @ 1:54 AM
Posts: 3,054, Visits: 4,009

Hi Alexander,

The code you posted does not modify the levels on the axes - therefore the code for custom ticks should work. Most likely it's not executed as we tested with log scale and the custom ticks appeared Ok. cna you post what is the target output you would like to achieve?



Best Regards,
Nevron Support Team



Alexander Konjaew
Posted 13 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 6, Visits: 1

ok, the chart is pretty good, so far. The custom tick is on the right position and looks like the other major ticks. Now, I would like to set the corresponding value on the axis, like in my screenshot.

Best regards,

Alex



Attachments
errorbar2.JPG (68 views, 55.00 KB)
Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: 2 days ago @ 1:54 AM
Posts: 3,054, Visits: 4,009

Hi Alexander,
You can use the configurator for this purpose:

NLinearScaleConfigurator scaleY = chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator as NLinearScaleConfigurator;
NCustomValueLabel customLabel = new NCustomValueLabel(10, "MyLabel");
customLabel.Style.TextStyle.FillStyle = new NColorFillStyle(Color.Red);
customLabel.Style.ZOrder = 1;
scaleY.CustomLabelFitModes = new LabelFitMode[] { LabelFitMode.RemoveOverlap };
scaleY.CustomLabels.Add(customLabel);
scaleY.CreateNewLevelForCustomLabels = false;

Note that you have to add the custom labels before you update the scale definition (UpdateScale). The above code creates a label that will remove the standart (auto label), in case it is overlapping with it.

 



Best Regards,
Nevron Support Team



Alexander Konjaew
Posted 13 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 6, Visits: 1

Due to the fact that my y axis has a logarithmic scale configurator I casted it to NScaleConfigurator. It works great!

Thank you very much for help!

Best regards,

Alexander





Similar Topics


Reading This Topic