前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >RadControls for Windows 8

RadControls for Windows 8

作者头像
全栈程序员站长
发布2022-09-09 11:48:32
3020
发布2022-09-09 11:48:32
举报
文章被收录于专栏:全栈程序员必看

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

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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档