繁体   English   中英

DynamicDataDisplay图表水平字符串轴

[英]DynamicDataDisplay chart horizontal string axis

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

我创建了自己的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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM