找回密码
 立即注册

QQ登录

只需一步,快速开始

kyb11111

中级会员

28

主题

72

帖子

534

积分

中级会员

积分
534

活字格认证

kyb11111
中级会员   /  发表于:2014-12-15 11:48  /   查看:11806  /  回复:14

点S1后 S1这条线隐藏 S1红框位置变灰

14 个回复

倒序浏览
Alice
社区贡献组   /  发表于:2014-12-15 16:00:00
沙发
回复 1楼kyb11111的帖子

通过DataSeries.Visibility属性设置为false隐藏掉该线。
代码参考:
  1.   XYDataSeries d1= this.c1Chart1.Data.Children[0] as XYDataSeries;
  2.             d1.MouseLeftButtonUp += new MouseButtonEventHandler(d1_MouseLeftButtonUp);
复制代码

事件代码:
  1. void d1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  2.         {
  3.             XYDataSeries ds = sender as XYDataSeries;
  4.             ds.Visibility = System.Windows.Visibility.Hidden;      
  5.             
  6.         }
复制代码

Legend里显示的S1颜色和线的颜色保持一致,所以需要将线的颜色设置为灰色。
参考代码:
  1.      Brush[] customBrushes = new Brush[2] { Brushes.Gray, Brushes.Blue};
  2.             c1Chart1.CustomPalette = customBrushes;
复制代码
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
kyb11111
中级会员   /  发表于:2014-12-16 17:06:00
板凳
回复 2楼Alice的帖子

我的意思是点击legend里的曲线名 不是chart里的曲线,legend有没有提供点击事件?
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2014-12-16 18:09:00
地板
回复 3楼kyb11111的帖子

可以在C1Chart里添加如下XMAL代码,可以在点击Legend区域时候触发d1_MouseLeftButtonUp事件:
  1.    <c1:C1ChartLegend Name="legned" MouseLeftButtonUp="d1_MouseLeftButtonUp">            
  2.             </c1:C1ChartLegend>
复制代码
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
kyb11111
中级会员   /  发表于:2014-12-16 20:27:00
5#
回复 4楼Alice的帖子

可以实现点legend里的S1Chart中S1隐藏  点legend里的S2 Chart中S2隐藏吗
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2014-12-17 11:17:00
6#
回复 5楼kyb11111的帖子

可以实现,通过重写Legend的ItemTemplate就可以很容易的做到,获取具体是哪个LegendItem被点击。
1.重写Legend的ItemTemplate,比如放个Label用来展示LegendItem的文字,并且挂上MouseLeftButtonUp事件。XMAL代码如下:
  1. <c1:C1ChartLegend Name="legned" >
  2.                 <c1:C1ChartLegend.ItemTemplate>
  3.                     <DataTemplate>
  4.                         <StackPanel Orientation="Horizontal">
  5.                             <Canvas  Width="24" Height="24" VerticalAlignment="Center">
  6.                                 <ContentControl Canvas.Top="11" Content="{Binding Path=Line}" Width="24" Height="20"/>
  7.                                 <ContentControl Canvas.Left="11" Canvas.Top="5" Content="{Binding Path=Symbol}" Width="14" Height="14"/>
  8.                             </Canvas>
  9.                             <Label Content="{Binding Path=Label}"  VerticalAlignment="Center"  MouseLeftButtonUp="Label_MouseLeftButtonUp"/>
  10.                         </StackPanel>
  11.                     </DataTemplate>
  12.                 </c1:C1ChartLegend.ItemTemplate>
  13.             </c1:C1ChartLegend>
复制代码

2.添加c#代码,当LegendItem被单击的时候,隐藏对应的XYDataSeries/DataSeries,并将圆形的标记更改颜色为灰色。
  1.   private void Label_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  2.         {
  3.             var cli = (sender as Label).DataContext as LegendItem;
  4.             if (cli != null)
  5.             {
  6.                 var ds = cli.Item as XYDataSeries;
  7.                 if (ds != null)
  8.                 {
  9.                     ds.Visibility = System.Windows.Visibility.Hidden;
  10.                     ds.SymbolFill = new SolidColorBrush(Colors.Gray);
  11.                 }
  12.             }
  13.         }
复制代码
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
kyb11111
中级会员   /  发表于:2014-12-17 11:44:00
7#
回复 6楼Alice的帖子

Thank you! Alice!
问题得到解决
回复 使用道具 举报
kyb11111
中级会员   /  发表于:2014-12-17 14:33:00
8#
回复 6楼Alice的帖子

<Canvas  Width="24" Height="24" VerticalAlignment="Center">
                                <ContentControl Canvas.Top="11" Content="{Binding Path=Line}" Width="24" Height="20"/>
                                <ContentControl Canvas.Left="11" Canvas.Top="5" Content="{Binding Path=Symbol}" Width="14" Height="14"/>
                            </Canvas>
这块代码 没起作用 显示到页面是空白的
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2014-12-17 18:25:00
9#
回复 8楼kyb11111的帖子

这是用来显示Legend的线和圆形标记的。
我这里显示是正常的,推测是否其他代码产生了影响,请检查排除其他的影响,如果还有问题。
可以把你做好的Demo发过来,我帮你看看原因。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
kyb11111
中级会员   /  发表于:2014-12-17 19:27:00
10#
回复 9楼Alice的帖子

能否发送项目过来
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部