zl程序教程

您现在的位置是:首页 >  系统

当前栏目

RadControls for Windows 8

Windows for RadControls
2023-06-13 09:12:17 时间

大家好,又见面了,我是你们的朋友全栈君。

RadControls for Windows 8

http://www.telerik.com/help/wpf/radchartview-populating-with-data-static-data.html

RadCartesianChart chart = new RadCartesianChart();

chart.HorizontalAxis = new CategoricalAxis(); chart.VerticalAxis = new LinearAxis() { Maximum = 100 };

LineSeries line = new LineSeries(); line.Stroke = new SolidColorBrush(Colors.Blue); line.StrokeThickness = 2; line.DataPoints.Add(new CategoricalDataPoint() { Value = 20 }); line.DataPoints.Add(new CategoricalDataPoint() { Value = 40 }); line.DataPoints.Add(new CategoricalDataPoint() { Value = 35 }); line.DataPoints.Add(new CategoricalDataPoint() { Value = 40 }); line.DataPoints.Add(new CategoricalDataPoint() { Value = 30 }); line.DataPoints.Add(new CategoricalDataPoint() { Value = 50 }); chart.Series.Add(line);

LineSeries line2 = new LineSeries(); line2.Stroke = new SolidColorBrush(Colors.Orange); line2.StrokeThickness = 2; line2.DataPoints.Add(new CategoricalDataPoint() { Value = 5 }); line2.DataPoints.Add(new CategoricalDataPoint() { Value = 44 }); line2.DataPoints.Add(new CategoricalDataPoint() { Value = 3 }); line2.DataPoints.Add(new CategoricalDataPoint() { Value = 55 }); line2.DataPoints.Add(new CategoricalDataPoint() { Value = 22 }); line2.DataPoints.Add(new CategoricalDataPoint() { Value = 11 }); chart.Series.Add(line2);

this.LayoutRoot.Children.Add(chart);

提示信息:

http://www.telerik.com/help/silverlight/radchartview-features-tooltip.html

<telerik:RadCartesianChart x:Name=”radCartesianChart” Margin=”8″ Grid.Row=”2″ Grid.ColumnSpan=”2″> <telerik:RadCartesianChart.Behaviors> <telerik:ChartTooltipBehavior Placement=”Top” /> </telerik:RadCartesianChart.Behaviors> <telerik:RadCartesianChart.TooltipTemplate> <DataTemplate> <Grid> <Path Data=”M-1236,-441 L-1180,-441 -1180,-424 -1228,-424 -1230.5,-420 -1233,-424 -1236,-424 z” Stretch=”Fill” Fill=”Beige” StrokeThickness=”2″/> <StackPanel Margin=”5,5,5,18″> <StackPanel Orientation=”Horizontal”> <TextBlock Text=” 值:” FontWeight=”Bold” FontSize=”11″/> <TextBlock Text=”{Binding Path=DataItem.Value}” FontWeight=”Bold” FontSize=”11″/> <TextBlock Text=” “/> </StackPanel> <StackPanel Orientation=”Horizontal”> <TextBlock Text=” 时间:” FontWeight=”Bold” FontSize=”11″/> <TextBlock Text=”{Binding Path=DataItem.Category}” FontWeight=”Bold” FontSize=”11″/> <TextBlock Text=” “/> </StackPanel> </StackPanel> </Grid> </DataTemplate> </telerik:RadCartesianChart.TooltipTemplate>

//标签模板

<telerik:LineSeries ShowLabels=”True” PointTemplate=”{StaticResource PointTemplate1}”> <telerik:LineSeries.LabelDefinitions> <telerik:ChartSeriesLabelDefinition> <telerik:ChartSeriesLabelDefinition.Template> <DataTemplate> <TextBlock Text=”MyTest”/> </DataTemplate> </telerik:ChartSeriesLabelDefinition.Template> </telerik:ChartSeriesLabelDefinition> </telerik:LineSeries.LabelDefinitions> <telerik:CategoricalDataPoint Category=”{x:Null}” IsSelected=”False” Label=”10″ Value=”10″/> <telerik:CategoricalDataPoint Category=”{x:Null}” IsSelected=”False” Label=”20″ Value=”20″/> <telerik:CategoricalDataPoint Category=”{x:Null}” IsSelected=”False” Label=”30″ Value=”30″/> </telerik:LineSeries>

代码:

#region //标签模板,显示标签 line.LabelDefinitions.Add(new ChartSeriesLabelDefinition { Template = (DataTemplate)XamlReader.Load(CreateItemTemplate()) }); #endregion

//点模板、标签模板、提示信息

<telerik:RadCartesianChart Margin=”10,10,8,0″ > <telerik:RadCartesianChart.Resources> <DataTemplate x:Key=”PointTemplate1″> <Ellipse x:Name=”ellipse” Height=”6″ Width=”6″ Fill=”Black”/> </DataTemplate> </telerik:RadCartesianChart.Resources> <telerik:RadCartesianChart.Behaviors> <telerik:ChartTooltipBehavior Placement=”Top” VerticalOffset=”20″/> </telerik:RadCartesianChart.Behaviors> <telerik:RadCartesianChart.TooltipTemplate> <DataTemplate> <Grid> <Path Data=”M-1236,-441 L-1180,-441 -1180,-424 -1228,-424 -1230.5,-420 -1233,-424 -1236,-424 z” Stretch=”Fill” Fill=”Beige” Stroke=”Gray” StrokeThickness=”2″/> <TextBlock Text=”Profit for ” FontWeight=”Bold” FontSize=”11″/> <TextBlock Text=”{Binding Path=DataItem.Value}” FontWeight=”Bold” FontSize=”11″/> </Grid> </DataTemplate> </telerik:RadCartesianChart.TooltipTemplate> <telerik:RadCartesianChart.HorizontalAxis> <telerik:CategoricalAxis/> </telerik:RadCartesianChart.HorizontalAxis> <telerik:RadCartesianChart.VerticalAxis> <telerik:LogarithmicAxis LabelOffset=”0″ LogarithmBase=”10″ LastLabelVisibility=”Visible” LineThickness=”1″ MajorTickOffset=”0″ TickThickness=”1″ ZIndex=”0″ ShowLabels=”False”/> </telerik:RadCartesianChart.VerticalAxis> <telerik:LineSeries ShowLabels=”True” PointTemplate=”{StaticResource PointTemplate1}”> <telerik:LineSeries.LabelDefinitions> <telerik:ChartSeriesLabelDefinition> <telerik:ChartSeriesLabelDefinition.Template> <DataTemplate> <TextBlock Text=”MyTest”/> </DataTemplate> </telerik:ChartSeriesLabelDefinition.Template> </telerik:ChartSeriesLabelDefinition> </telerik:LineSeries.LabelDefinitions> <telerik:CategoricalDataPoint Category=”{x:Null}” IsSelected=”False” Label=”10″ Value=”10″/> <telerik:CategoricalDataPoint Category=”{x:Null}” IsSelected=”False” Label=”20″ Value=”20″/> <telerik:CategoricalDataPoint Category=”{x:Null}” IsSelected=”False” Label=”30″ Value=”30″/> </telerik:LineSeries> <telerik:LineSeries ShowLabels=”True”> <telerik:CategoricalDataPoint Category=”{x:Null}” IsSelected=”False” Label=”10″ Value=”50″/> <telerik:CategoricalDataPoint Category=”{x:Null}” IsSelected=”False” Label=”1111″ Value=”30″/> <telerik:CategoricalDataPoint Category=”{x:Null}” IsSelected=”False” Label=”30″ Value=”30″/> </telerik:LineSeries> </telerik:RadCartesianChart>

//代码添加模板

var pointTemplate = chartObject.Resources[“PointTemplate1”] as DataTemplate; //获取xaml中的模板对象

#region //标签模板,显示标签 line.LabelDefinitions.Add(new ChartSeriesLabelDefinition { Template = (DataTemplate)XamlReader.Load(CreateItemTemplate(c.ToString())) }); #endregion

private string CreateItemTemplate(string strColor) { string strText = string.Format(“<TextBlock Text=\”{0}\” Foreground=\”{1}\” Margin=\”0,0,0,0\”/>”, “{Binding Label}”, strColor); StringBuilder template = new StringBuilder(); template.Append(“<DataTemplate “); template.Append(“xmlns=’http://schemas.microsoft.com/winfx/”); template.Append(“2006/xaml/presentation’ “); template.Append(“xmlns:x=’http://schemas.microsoft.com/winfx/2006/xaml’>”);

//template.Append(“<Grid>”); //template.Append(“<Path Data=\”M-1236,-441 L-1180,-441 -1180,-424 -1228,-424 -1230.5,-420 -1233,-424 -1236,-424 z\” Stretch=\”Fill\” Fill=\”Beige\” Stroke=\”Gray\” StrokeThickness=\”2\”/>”); //template.Append(“<TextBlock Text=\”{Binding Label}\” Foreground=\”{Binding m_listColors}\” Margin=\”0,0,0,0\”/>”); //template.Append(“</Grid>”);

template.Append(strText);

template.Append(“</DataTemplate>”); return template.ToString(); }

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/162012.html原文链接:https://javaforall.cn