Group: Forum Members
Last Active: 11 Years Ago
Posts: 7,
Visits: 1
|
Hello,
I have a bar chart where the Y axis measures a distance between 0 and, say, 300 cm. I need a way to rescale the Y-Axis maximum value whenever a value comes in above the current maximum on the Y-Axis scale. I'm currently doing this by brute force, but I suspect there's an easier way of doing this using an existing Nevron chart feature, similar to what is described here:
http://support.nevron.com/KB/a219/create-a-custom-axis-view-that-updates-the-y-axis-range.aspx
Here's the relevant parts of my code. The AddBarData() method determines if the length (Y-Axis value) exceeds the maximum scale. If so, it calculates a new Y-Axis maximum value, then calls SetChart to redraw the chart with the new scale. The downside to this method, is I keep a running history of the bar values, and force a redraw. This probably isn't necessary, hence my question.
Thanks for any and all help on this.
public partial class NevronChart : UserControl, INevronChart { NChart chart; NBarSeries barSeries; NLabel title; bool bDisplayOrthogonal; bool bMetric; double MaxLength; double MaxTimeOfFlight; double[] datapoint;
public void SetChart(bool bOrthogonal, bool bDefault, bool bIsMetric) { NLinearScaleConfigurator yScale = new NLinearScaleConfigurator(); bDisplayOrthogonal = bOrthogonal;
ClearData();
if (bDefault) { MaxLength = 300.0; // centimeters } barSeries.Name = "Length"; AddTitle("Length");
// Setup Y axis yScale.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true); yScale.MajorGridStyle.SetShowAtWall(ChartWallType.Left, true); yScale.MajorGridStyle.LineStyle.Pattern = LinePattern.Solid;
// Setup Y ticks // Setting the text of the title. if (bIsMetric) yScale.Title.Text = "Length (cm)"; else yScale.Title.Text = "Length (in)";
// Setting the angle between the axis and the title. yScale.Title.Angle = new NScaleLabelAngle(-90);
// Setting the offset of the axis title. yScale.Title.Offset = new NLength(0);
// Setting the title alignment. // yScale.Title.RulerAlignment = Nevron.HorzAlign.Center;
// Setting the title ruler offset. yScale.Title.RulerOffset = new NLength(2, NRelativeUnit.ParentPercentage);
// Setting the title content alignment. yScale.Title.ContentAlignment = ContentAlignment.MiddleCenter;
yScale.MajorTickMode = MajorTickMode.CustomStep; // AutoMaxCount if (bIsMetric) { yScale.CustomStep = 20; yScale.AutoMinorTicks = true; yScale.MinorTickCount = 1; yScale.MinTickDistance = new NLength(10); yScale.UseOrigin = true; } else { yScale.CustomStep = 10; yScale.AutoMinorTicks = true; yScale.MinorTickCount = 1; yScale.MinTickDistance = new NLength(10); yScale.UseOrigin = true; }
yScale.LabelValueFormatter = new NNumericValueFormatter("#.##"); // ???? chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator = yScale; if (bIsMetric) chart.Axis(StandardAxis.PrimaryY).View = new NRangeAxisView(new NRange1DD(0.0, MaxLength), true, true); else chart.Axis(StandardAxis.PrimaryY).View = new NRangeAxisView(new NRange1DD(0.0, MaxLength/2.54), true, true); }
ApplyLayoutTemplate(0, chart, title, null); }
public bool AddBarData(double[] safearray, int idx) {
int i;
double maxheight = (bMetric) ? MaxHeight : MaxHeight / 2.54; if (safearray[idx + 1] > maxheight) { int cnt = (int)safearray[idx] - 1;
if (bMetric) MaxHeight = maxheight + 10; else MaxHeight = (maxheight * 2.54) + 10; this.SetChart(true, false, bMetric); ClearData(); for (i = 0; i < cnt; i++) barSeries.AddDataPoint(new NDataPoint((double)i + 0.5, datapoint[i])); // 1..10 }
datapoint[(int)(safearray[idx] - 1.0)] = safearray[idx + 1];
barSeries.AddDataPoint(new NDataPoint(safearray[idx] - 0.5, safearray[idx + 1])); // 1..10
nChartControl1.Refresh();
return (false); } }
|