嗨,我想知道如何设置 X 轴和 y 轴的标签?
现在,我有一个带有值的图表,并且我格式化了工具提示,但我不知道如何为 X 和 Y 轴设置标签。
另一件事是,是否可以在图表系列中执行缩放,我的意思是,如果我的 x 轴以年为单位,我想将其更改为月,或者学期和新点需要出现在行中?如果这是可能的,是不是太难了?
我无法设置 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);
它会给我这个结果。
替代文字 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.
}