【问题标题】:How to Hide or Remove Zero values in line series RadChart如何隐藏或删除线系列 RadChart 中的零值
【发布时间】:2013-01-30 08:48:41
【问题描述】:

我正在使用 Radchart,我想删除显示值为零的线系列。是否有任何可能的方法来隐藏或删除显示为零的值。请提供任何解决方案或代码。

提前致谢。

【问题讨论】:

  • 我从未使用过 Radchart,但有几件事可能会有所帮助,您是否尝试过使用值转换器不返回任何值以便它可能抑制零?你试过 Telerik 支持论坛吗?
  • 是的,我在 Telerik 支持论坛中尝试过,但还没有回复。

标签: asp.net wcf silverlight-4.0 telerik radchart


【解决方案1】:

经过 2 天的努力,我找到了如何隐藏或删除包含零的线系列的解决方案。我在第 4 线系列中有四个线系列包含零,我想隐藏那些零值,我已经完成了.

实施前

实施后

代码

             //-------------------Styling------------------------           
        RadChart1.DefaultView.ChartLegend.Background = new SolidColorBrush(Color.FromArgb(255, 75, 119, 255));

        RadChart1.DefaultView.ChartArea.AxisY.StripLinesVisibility = Visibility.Collapsed;
        RadChart1.DefaultView.ChartArea.AxisY.MajorGridLinesVisibility = Visibility.Visible;

        RadChart1.DefaultView.ChartLegend.UseAutoGeneratedItems = true;
        RadChart1.DefaultView.ChartLegend.Header = "";


        RadChart1.DefaultView.ChartLegendPosition = Telerik.Windows.Controls.Dock.Bottom;
        RadChart1.DefaultView.ChartLegend.Foreground = new SolidColorBrush(Colors.White);
        RadChart1.DefaultView.ChartLegend.LegendItemStyle = new Style() { TargetType = typeof(ChartLegendItem) };
        RadChart1.DefaultView.ChartLegend.LegendItemStyle.Setters.Add(new Setter() { Property = Control.ForegroundProperty, Value = new SolidColorBrush(Colors.White) });


        ChartLegendItem ch1 = new ChartLegendItem() { Label = "FY10", Background = new SolidColorBrush(Colors.Blue), Foreground = new SolidColorBrush(Colors.White) };
        ChartLegendItem ch2 = new ChartLegendItem() { Label = "FY11", Background = new SolidColorBrush(Colors.Brown), Foreground = new SolidColorBrush(Colors.White) };
        ChartLegendItem ch3 = new ChartLegendItem() { Label = "FY12", Background = new SolidColorBrush(Colors.Green), Foreground = new SolidColorBrush(Colors.White) };
        ChartLegendItem ch4 = new ChartLegendItem() { Label = "FY13", Background = new SolidColorBrush(Colors.Black), Foreground = new SolidColorBrush(Colors.White) };

        ChartLegendItemCollection chC = new ChartLegendItemCollection();
        chC.Add(ch1);
        chC.Add(ch2);
        chC.Add(ch3);
        chC.Add(ch4);

        RadChart1.DefaultView.ChartLegend.UseAutoGeneratedItems = false;
        RadChart1.DefaultView.ChartLegend.Items.Clear();
        RadChart1.DefaultView.ChartLegend.Items.Add(chC[0]);
        RadChart1.DefaultView.ChartLegend.Items.Add(chC[1]);
        RadChart1.DefaultView.ChartLegend.Items.Add(chC[2]);
        RadChart1.DefaultView.ChartLegend.Items.Add(chC[3]);

        Style pathStyle1 = new Style(typeof(System.Windows.Shapes.Path));
        pathStyle1.Setters.Add(new Setter(Shape.StrokeProperty, new SolidColorBrush(Colors.Blue)));
        pathStyle1.Setters.Add(new Setter(Shape.StrokeThicknessProperty, 2));

        Style lineStyle1 = new Style(typeof(Telerik.Windows.Controls.Charting.LineSeries));
        lineStyle1.Setters.Add(new Setter(LineSeries.BorderLineStyleProperty, pathStyle1));

        Style pathStyle2 = new Style(typeof(System.Windows.Shapes.Path));
        //  pathStyle2.Setters.Add(new Setter(Shape.StrokeDashArrayProperty, "1"));
        pathStyle2.Setters.Add(new Setter(Shape.StrokeProperty, new SolidColorBrush(Colors.Brown)));
        pathStyle2.Setters.Add(new Setter(Shape.StrokeThicknessProperty, 2));

        Style lineStyle2 = new Style(typeof(Telerik.Windows.Controls.Charting.SelfDrawingSeries));
        lineStyle2.Setters.Add(new Setter(SelfDrawingSeries.BorderLineStyleProperty, pathStyle2));

        Style pathStyle3 = new Style(typeof(System.Windows.Shapes.Path));
        //  pathStyle3.Setters.Add(new Setter(Shape.StrokeDashArrayProperty, "1"));
        pathStyle3.Setters.Add(new Setter(Shape.StrokeProperty, new SolidColorBrush(Colors.Green)));
        pathStyle3.Setters.Add(new Setter(Shape.StrokeThicknessProperty, 2));

        Style lineStyle3 = new Style(typeof(Telerik.Windows.Controls.Charting.SelfDrawingSeries));
        lineStyle3.Setters.Add(new Setter(SelfDrawingSeries.BorderLineStyleProperty, pathStyle3));


        Style pathStyle4 = new Style(typeof(System.Windows.Shapes.Path));
        //pathStyle4.Setters.Add(new Setter(Shape.StrokeDashArrayProperty, "1"));
        pathStyle4.Setters.Add(new Setter(Shape.StrokeProperty, new SolidColorBrush(Colors.Black)));
        pathStyle4.Setters.Add(new Setter(Shape.StrokeThicknessProperty, 2));

        Style lineStyle4 = new Style(typeof(Telerik.Windows.Controls.Charting.SelfDrawingSeries));
        lineStyle4.Setters.Add(new Setter(SelfDrawingSeries.BorderLineStyleProperty, pathStyle4));

        DataSeries line1 = new DataSeries() { Definition = new LineSeriesDefinition() { ShowItemLabels = false, ShowPointMarks = false, SeriesStyle = lineStyle1 } };
        DataSeries line2 = new DataSeries() { Definition = new LineSeriesDefinition() { ShowItemLabels = false, ShowPointMarks = false, SeriesStyle = lineStyle2 } };
        DataSeries line3 = new DataSeries() { Definition = new LineSeriesDefinition() { ShowItemLabels = false, ShowPointMarks = false, SeriesStyle = lineStyle3 } };
        DataSeries line4 = new DataSeries() { Definition = new LineSeriesDefinition() { ShowItemLabels = false, ShowPointMarks = false, SeriesStyle = lineStyle4 } };


        //-------------------------Data Binding---------------------------
        List< WebService. RadChart1Data > objListAPS = new List<WebService.RadChart1Data>();
        objListAPS = (List< WebService. RadChart1Data >)e.Result.ToList();

        foreach (RadChart1Data obj in objListAPS)
        {
            line1.Add(new DataPoint(obj.Week, obj.BlueLine));
            line2.Add(new DataPoint(obj.Week, obj.RedLine));
            line3.Add(new DataPoint(obj.Week, obj.GreenLine));
            if (obj.BlackLine != 0)
                line4.Add(new DataPoint(obj.Week, obj. BlackLine));
        }

        RadChart1.DefaultView.ChartArea.DataSeries.Add(line1);
        RadChart1.DefaultView.ChartArea.DataSeries.Add(line2);
        RadChart1.DefaultView.ChartArea.DataSeries.Add(line3);
        RadChart1.DefaultView.ChartArea.DataSeries.Add(line4);

        RadChart1.DefaultView.ChartArea.AxisX.LayoutMode =  Telerik.Windows.Controls.Charting.AxisLayoutMode.Inside;

如果有人发现此答案有用,请将其标记为正确答案,它可能对其他人有帮助。

谢谢

迪内什·哈拉维尔

【讨论】:

  • 唯一可以将其标记为正确的是您。您可能需要等待一段时间,因为您自己回答了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-23
  • 2017-09-30
  • 1970-01-01
  • 2018-12-26
  • 2018-09-10
相关资源
最近更新 更多