我需要使用DynamicDataDisplay3绘制一些图表。一切正常,除了我找不到将X轴更改为字符串而不是日期或整数的方法。这就是我尝试这样做的方法,但我在X轴上只得到1个值:
int i = 0;
using (MySqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
i++;
Analyze build = new Analyze();
build.id = i;
build.build = Convert.ToString(reader[0]);
builds.Add(build);
n1.Add(Convert.ToInt32(reader[1]));
}
}
var datesDataSource = new EnumerableDataSource<Analyze>(builds);
datesDataSource.SetXMapping(x => x.id);
var numberOpenDataSource = new EnumerableDataSource<int>(n1);
numberOpenDataSource.SetYMapping(y => y);
CompositeDataSource compositeDataSource1 = new CompositeDataSource(datesDataSource, numberOpenDataSource);
chBuild.AddLineGraph(compositeDataSource1, new Pen(Brushes.Blue, 2), new CirclePointMarker { Size = 6, Fill = Brushes.Blue }, new PenDescription(Convert.ToString(cmbBuildVertical.SelectedItem)));
chBuild.Viewport.FitToView();
答案 0 :(得分:2)
我制作了自己的LabelProvider来处理与此类似的事情。我想将我的DateTime标签覆盖为整数,以表示不同的东西。在你的情况下,你可以使用这样的东西:
public class StringLabelProvider : NumericLabelProviderBase {
private List<String> m_Labels;
public List<String> Labels {
get { return m_Labels; }
set { m_Labels = value; }
}
/// <summary>
/// Initializes a new instance of the <see cref="ToStringLabelProvider"/> class.
/// </summary>
public StringLabelProvider(List<String> labels) {
Labels = labels;
}
public override UIElement[] CreateLabels(ITicksInfo<double> ticksInfo) {
var ticks = ticksInfo.Ticks;
Init(ticks);
UIElement[] res = new UIElement[ticks.Length];
LabelTickInfo<double> tickInfo = new LabelTickInfo<double> { Info = ticksInfo.Info };
for (int i = 0; i < res.Length; i++) {
tickInfo.Tick = ticks[i];
tickInfo.Index = i;
string labelText = "";
labelText = Labels[Convert.ToInt32(tickInfo.Tick)];
TextBlock label = (TextBlock)GetResourceFromPool();
if (label == null) {
label = new TextBlock();
}
label.Text = labelText;
res[i] = label;
ApplyCustomView(tickInfo, label);
}
return res;
}
}
您可以构建刻度列表,并将其发送到您创建的LabelProvider。像这样:
StringLabelProvider labelProvider = new StringLabelProvider(yourLabelList);
yourAxis.LabelProvider = labelProvider;