【问题标题】:How can set the y and x axis of a wpf toolkit chart? something like y:kg, x:years如何设置 wpf 工具包图表的 y 轴和 x 轴?像 y:kg, x:years
【发布时间】:2010-03-03 09:29:51
【问题描述】:

您好,我想知道如何设置 X 轴和 y 轴的标签?

现在,我有一个带有值的图表,我格式化了工具提示,但我不知道如何设置 X 和 Y 轴的标签。

另一件事是,是否可以放大图表系列,我的意思是,如果我的 x 轴以年为单位,我想将其更改为月,或者学期和新点需要出现在行中?如果这是可能的,是不是太难了?

【问题讨论】:

    标签: c# wpf charts toolkit


    【解决方案1】:

    我无法设置 y 轴的标签(我认为不可能),但您可以使用 Title 属性在图例上设置它。在 x 轴上,它取决于 DataPointSeries'IndependentValueBinding 上的绑定集。

    假设在这个示例中,我创建了一个类对象,它将代表每个记录/数据点。

    public class ChartInfo
    {
        public string Label { get; set; }
        public double Value { get; set; }
    }
    

    然后我有这个代码:

    List<ChartInfo> list = new List<ChartInfo>();
    ChartInfo item = new ChartInfo();
    item.Label = "Individual";
    item.Vale = 27;
    list.Add(item);
    item = new ChartInfo();
    item.Label = "Corporate";
    item.Vale = 108;
    list.Add(item);
    
    DataPointSeries series = new ColumnSeries();
    series.Title = "Quantity";
    series.DependentValueBinding = new Binding("Value");
    series.IndependentValueBinding = new Binding("Label");
    series.ItemsSource = list;
    series.SelectionChanged += new SelectionChangedEventHandler(series_SelectionChanged);
    this.chartingToolkitControl.Series.Add(series);
    

    它会给我这个结果。

    alt text http://www.freeimagehosting.net/uploads/78e2598620.jpg

    对于缩放 - 我认为正确的术语是向下钻取。您可以使用 SelectionChanged 事件(参见上面的代码)。您应该做的是重新查询您的数据源并清除图表的系列并根据您的查询结果添加一个新的系列。

    private void series_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //The sender here is of type DataPointSeries wherein you could get the SelectedItem (in our case ChartInfo) and from there you could do the requery.
        }
    

    【讨论】:

    • 感谢您的回答,对我很有帮助。而且我没想到会以这种方式放大。谢谢。
    • @Clerks - 如果答案对您有帮助,请不要忘记投票并将其标记为您问题的已接受答案:)
    猜你喜欢
    • 2014-05-13
    • 1970-01-01
    • 1970-01-01
    • 2019-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多