动态数据显示图表水平字符串轴

本文关键字:字符串 水平 数据 显示图 动态 | 更新日期: 2023-09-27 18:04:46

我需要使用DynamicDataDisplay3绘制一些图表。一切都很好,除了我找不到一种方法来改变X轴字符串而不是日期或整数。这就是我尝试的方法但是我在X轴上只得到一个值:

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

动态数据显示图表水平字符串轴

我制作了自己的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;