1

我需要使用 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();
4

1 回答 1

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;
于 2013-03-21T18:56:08.597 回答