0

I'm using Telerik RadChart for drawing a line chart. Everything is OK except Zero value don't show up as attached.

enter image description here enter image description here

Is there an appearance property that is responsible of this behavior?

I'm creating the control like this:

    /// <summary>
    /// builds the chart object
    /// </summary>
    /// <param name="chartSeriesItems">Series Items For index values</param>
    /// <param name="chartAvrageSeriesItems">Avrage 2 seies items for start and end</param>
    /// <returns></returns>
    private RadChart BuildChart(List<ChartSeriesItem> chartSeriesItems, List<ChartSeriesItem> chartAvrageSeriesItems)
    {
        RadChart chart = new RadChart();

        chart.ID = "SparklineChart";
        chart.Width = 200;
        chart.Height = 140;
        chart.DefaultType = ChartSeriesType.Line;
        chart.AutoLayout = true;
        chart.ChartTitle.Visible = false;

        chart.Appearance.Dimensions.Margins = ChartMargins.Parse("0px, 0px, 0px, 0px");
        chart.Appearance.Dimensions.Paddings = ChartPaddings.Parse("0px, 0px, 0px, 0px");
        chart.Appearance.Dimensions.AutoSize = true;
        chart.Appearance.Dimensions.Height = 140;
        chart.Appearance.Dimensions.Width = 200;
        chart.Appearance.FillStyle.FillType = FillType.Solid;
        chart.Appearance.FillStyle.MainColor = Color.Transparent;
        chart.Appearance.Border.Visible = false;


        chart.Legend.Visible = false;

        chart.PlotArea.XAxis.Visible = ChartAxisVisibility.False;
        chart.PlotArea.YAxis.Visible = ChartAxisVisibility.False;
        chart.PlotArea.Appearance.Dimensions.Margins = ChartMargins.Parse("0px, 0px, 0px, 0px");
        chart.PlotArea.Appearance.Dimensions.Paddings = ChartPaddings.Parse("0px, 0px, 0px, 0px");
        chart.PlotArea.Appearance.FillStyle.FillType = FillType.Solid;
        chart.PlotArea.Appearance.FillStyle.MainColor = Color.Transparent;
        chart.PlotArea.Appearance.Border.Visible = false;
        chart.PlotArea.EmptySeriesMessage.TextBlock.Appearance.AutoTextWrap = AutoTextWrap.True;
        chart.PlotArea.EmptySeriesMessage.TextBlock.Text = Resources.Text.NoData;


        //add series
        ChartSeries scoreSeries = new ChartSeries();
        scoreSeries.Name = "Score";
        scoreSeries.DefaultLabelValue = "#Y" + FormatText.GetFormat(Global.GetUserProfile().NumbersFormat, Global.GetUserProfile().DecimalDigits).Replace("0:", "");
        scoreSeries.Appearance.FillStyle.MainColor = Color.Black;
        scoreSeries.Appearance.LabelAppearance.Visible = true;
        scoreSeries.Type = ChartSeriesType.Line;
        scoreSeries.Items.AddRange(chartSeriesItems);

        ChartSeries avrageSeries = new ChartSeries();
        avrageSeries.Name = "Avrage";
        avrageSeries.DefaultLabelValue = "#Y" + FormatText.GetFormat(Global.GetUserProfile().NumbersFormat, Global.GetUserProfile().DecimalDigits).Replace("0:", "");
        avrageSeries.Appearance.FillStyle.MainColor = Color.Gray;
        avrageSeries.Appearance.LabelAppearance.Visible = true;
        avrageSeries.Type = ChartSeriesType.Line;
        avrageSeries.Appearance.LineSeriesAppearance.Width = 1;
        avrageSeries.Items.AddRange(chartAvrageSeriesItems);



        chart.Series.Add(scoreSeries);
        chart.Series.Add(avrageSeries);

        return chart;
    }

And I'm adding values like this:

 ChartSeriesItem seriesItem = new ChartSeriesItem()
                            {
                                Name = "1",
                                XValue = index++,
                                YValue = 200
                            };
                        totalYValue += 200;
                        seriesItem.Label.Appearance.FillStyle.MainColor = SAObjectsUtilities.GetColorFromStatus(SA_Globals.Status.Blue);
                        //seriesItem.Label.TextBlock.Appearance.TextProperties.Color = SAObjectsUtilities.GetLabelForeGroundColor(item.ScoreStatus);
                        seriesItem.Label.TextBlock.Appearance.TextProperties.Font = new Font(new FontFamily("Arial"), 7);
                        seriesItem.Label.TextBlock.Appearance.TextProperties.Color = Color.Black;
                        chartSeriesItems.Add(seriesItem);




                        ChartSeriesItem seriesItem2 = new ChartSeriesItem()
                        {
                            Name = "2",
                            XValue = index++,
                            YValue = 0
                        };
                        totalYValue += 0;
                        seriesItem2.Label.Appearance.FillStyle.MainColor = SAObjectsUtilities.GetColorFromStatus(SA_Globals.Status.Red);
                        //seriesItem.Label.TextBlock.Appearance.TextProperties.Color = SAObjectsUtilities.GetLabelForeGroundColor(item.ScoreStatus);
                        seriesItem2.Label.TextBlock.Appearance.TextProperties.Font = new Font(new FontFamily("Tahoma"), 7);
                        seriesItem2.Label.TextBlock.Appearance.TextProperties.Color = Color.Black;
                        chartSeriesItems.Add(seriesItem2);
AHMED EL-HAROUNY
  • 836
  • 6
  • 17
  • I got the same issue using Bar Chart...have you found a work around? – Francis P Nov 27 '12 at 15:45
  • yes I think I had found a workaround by overriding the label and add the 0 myself. but actully I'm not sure as it was long time ago and I don't have access to the code base right now – AHMED EL-HAROUNY Dec 05 '12 at 04:55

1 Answers1

0

If anybody encounters the same issue:

I ended up using an adjusted value (So if the value is 0, I use 0.001) so it actually renders the point (or Bar in my case) and then use my own string property for the label's value.

    private static decimal MIN_GRAPH_VALUE = new decimal(0.001);
    public decimal AjustedValue
    {
        get { return (_value.Equals(0)) ? MIN_GRAPH_VALUE : _value; }
    }
    public string StringValue
    {
        get { return _value.ToString("0.00%"); }
    }

And for the BarSeries bindings:

<telerik:BarSeries Name="My value" Stacked="false" DataFieldY="AjustedValue">
    <Appearance>
        <FillStyle BackgroundColor="#92b622"></FillStyle>
    </Appearance>
    <LabelsAppearance ClientTemplate='#=dataItem.StringValue#' Position="OutsideEnd">
    </LabelsAppearance>
</telerik:BarSeries>
Francis P
  • 13,377
  • 3
  • 27
  • 51