在我的 Windows Phone 通用应用程序中,我试图在 y 轴上添加散点系列。我在图表上动态添加系列,然后使用最小值、最大值和间隔设置比例。在某些情况下,当间隔变得大于 10 时,图表比例不会按需要出现。请帮忙。提前致谢。
DateTimeAxis x = new DateTimeAxis() { Orientation = AxisOrientation.X, Location = AxisLocation.Bottom };
string InterValType = "";
int interval = 0;
CalulateInterValForDateAxis(DictVarData.ElementAt(DictVarData.Count - 1).Name, DictVarData.ElementAt(0).Name, ref InterValType, ref interval);
x.Interval = interval;
x.IntervalType = InterValType == "Days" ? DateTimeIntervalType.Days : InterValType == "Months" ? DateTimeIntervalType.Months : DateTimeIntervalType.Years;
Style st = new Style(typeof(DateTimeAxisLabel));
st.Setters.Add(new Setter(DateTimeAxisLabel.StringFormatProperty, "{0:MM/dd/yy}"));
st.Setters.Add(new Setter(DateTimeAxisLabel.FontSizeProperty, "10"));
st.Setters.Add(new Setter(DateTimeAxisLabel.ForegroundProperty, "Black"));
x.AxisLabelStyle = st;
Style stmin = new Style(typeof(Line));
stmin.Setters.Add(new Setter(Line.HeightProperty, "10"));
stmin.Setters.Add(new Setter(Line.StrokeProperty, "Black"));
stmin.Setters.Add(new Setter(Line.StrokeThicknessProperty, "2"));
stmin.Setters.Add(new Setter(Line.X1Property, "0"));
stmin.Setters.Add(new Setter(Line.X2Property, "10"));
stmin.Setters.Add(new Setter(Line.Y1Property, "0"));
stmin.Setters.Add(new Setter(Line.Y2Property, "10"));
x.MajorTickMarkStyle = stmin;
LinearAxis y = new LinearAxis() { Orientation = AxisOrientation.Y, Location = AxisLocation.Left, Minimum = YMinValue, Maximum = YMaxValue,Interval=YInterval };
y.FontSize = 10;
y.ShowGridLines = true;
y.Margin = new Thickness(0);
y.Foreground = new SolidColorBrush(Colors.Black);
this.ScatterChart.Axes.Add(y);
ScatterSeries ScatterS = new ScatterSeries();
for (int cntY = 0; cntY < General.VariableArrayYAxis.Count; cntY++)
{
if (cntY != 0)
ScatterS = new ScatterSeries();
ScatterS.DependentValuePath = "Value";
ScatterS.IndependentValuePath = "Name";
ScatterS.Name = General.VariableArrayYAxis[cntY].ToString();
ScatterS.DataPointStyle = (Style)App.Current.Resources[GetStyleName(dictColorUsedForVariable[General.VariableArrayYAxis[cntY]])];
this.ScatterChart.Series.Add(ScatterS);
}
this.ScatterChart.Axes.Add(x);
this.ScatterChart.Background = new SolidColorBrush(Colors.White);
ScatterS.DependentRangeAxis = this.ScatterChart.ActualAxes[0] as DateTimeAxis;
ScatterS.DependentRangeAxis = this.ScatterChart.ActualAxes[1] as LinearAxis;