简体   繁体   English

如何设置WPF工具包图表的y和x轴? 类似于y:kg,x:years

[英]How can set the y and x axis of a wpf toolkit chart? something like y:kg, x:years

Hi I would like to know how can i do to set the label for X axis and y axis? 嗨,我想知道如何设置X轴和y轴的标签?

Righ now, i have a chart with the values, and I format the tooltip, but i can't realize how to set the label for X an Y axis. 现在,我有一个带有值的图表,并且格式化了工具提示,但是我不知道如何为X和Y轴设置标签。

Another thing is, Is posible to execute zooming in a chart series, I mean, if i have the x axis in years, i would like to change it to months, or semesters and new points need to appear in the line? 另一件事是,是否可以在图表系列中执行缩放,我的意思是,如果我的x轴以年为单位,我想将其更改为几个月,或者需要在该行中显示学期和新点? if this is posible, is too dificult to do it? 如果这是可行的,那么难吗?

I haven't able to set the label of the y axis (I don't think its possible) but you could set it on the legend using the Title property. 我无法设置y轴的标签(我认为不可能),但是您可以使用Title属性在图例上进行设置。 On the x axis it depends on the binding set on your DataPointSeries'IndependentValueBinding. 在x轴上,它取决于在DataPointSeries'IndependentValueBinding上设置的绑定。

Lets say on this sample I have created a class object that will represent every record/datapoint. 可以说,在此示例中,我创建了一个类对象,它将代表每个记录/数据点。

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

Then I have this code: 然后我有这段代码:

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

It will give me this result. 它会给我这个结果。

alt text http://www.freeimagehosting.net/uploads/78e2598620.jpg 替代文字http://www.freeimagehosting.net/uploads/78e2598620.jpg

For the zooming - I think the right term is drill-down. 对于缩放-我认为正确的术语是向下钻取。 You could use the SelectionChanged event (see the code above). 您可以使用SelectionChanged事件(请参见上面的代码)。 What you should do is requery your datasource and clear the graph's series and add a new one based on your query result. 您应该做的是重新查询数据源并清除图形的序列,然后根据查询结果添加一个新的序列。

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.
    }

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

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