0

I have a problem with my RadHtmlChart. It's very easy to understand, my chart (title, axis, axis name, ...) doesn't display when I add LineSeries programmatically with foreach loop but display without and I don't understand why.

Here is my asp.net code

<telerik:RadHtmlChart runat="server" ID="LineChart" Width="800" Height="500" Transitions="true" Skin="Silk">
    <Appearance>
        <FillStyle BackgroundColor="Transparent"></FillStyle>
    </Appearance>
    <ChartTitle>
        <Appearance Align="Center" BackgroundColor="Transparent" Position="Top">
        </Appearance>
    </ChartTitle>
    <Legend>
        <Appearance BackgroundColor="Transparent" Position="Bottom">
        </Appearance>
    </Legend>
    <PlotArea>
        <Appearance>
            <FillStyle BackgroundColor="Transparent"></FillStyle>
        </Appearance>
        <XAxis AxisCrossingValue="0" Color="black" MajorTickType="Outside" MinorTickType="Outside"
            Reversed="false">
            <Items>
            </Items>
            <LabelsAppearance DataFormatString="{0}" RotationAngle="0" Skip="0" Step="1">
            </LabelsAppearance>
            <TitleAppearance Position="Center" RotationAngle="0">
            </TitleAppearance>
        </XAxis>
        <YAxis AxisCrossingValue="0" Color="black" MajorTickSize="1" MajorTickType="Outside"
            MaxValue="100" MinorTickSize="1" MinorTickType="Outside" MinValue="0" Reversed="false"
            Step="25">
            <LabelsAppearance DataFormatString="{0}" RotationAngle="0" Skip="0" Step="1">
            </LabelsAppearance>
            <TitleAppearance Position="Center" RotationAngle="0">
            </TitleAppearance>
        </YAxis>
    </PlotArea>
</telerik:RadHtmlChart>

C# code-behind which doesn't display chart with loop

protected void BuildChartYear(int year)
{
    foreach (TypesFichesDbo typeFiche in typesFiches)
    {
        LineSeries line = new LineSeries();
        line.Name = typeFiche.Nom;
        System.Drawing.Color color = System.Drawing.ColorTranslator.FromHtml(GetColorTypeFiche(typeFiche.Valeur));
        line.Appearance.FillStyle.BackgroundColor = color;
        line.LabelsAppearance.DataFormatString = "{0}";
        line.LabelsAppearance.Position = Telerik.Web.UI.HtmlChart.LineAndScatterLabelsPosition.Above;
        line.LineAppearance.Width = 1;
        line.MarkersAppearance.MarkersType = Telerik.Web.UI.HtmlChart.MarkersType.Circle;
        line.MarkersAppearance.BackgroundColor = System.Drawing.Color.White;
        line.MarkersAppearance.Size = 8;
        line.MarkersAppearance.BorderColor = color;
        line.MarkersAppearance.BorderWidth = 2;
        line.TooltipsAppearance.DataFormatString = "{0}";

        IList<FichesDbo> fiches = DaoManager.Instance.FichesDao.GetFichesFromChantier(CurrentChantier.Id);
        for (int month = 1; month <= 12; month++)
        {
            CategorySeriesItem item = new CategorySeriesItem(fiches.Where(x => x.DateEvenement.Value.Month == month)
                .Where(y => y.DateEvenement.Value.Year == year)
                .Where(z => z.Type.Id == typeFiche.Id).ToList().Count, color);
            line.SeriesItems.Add(item);
        }
        line.MissingValues = Telerik.Web.UI.HtmlChart.MissingValuesBehavior.Zero;
        LineChart.PlotArea.Series.Add(line);
    }
    LineChart.ChartTitle.Text = string.Format(Resources.MainResources.sheetsNumber + " : {0}", year.ToString());
    LineChart.DataBind();
}

and C# code-behind which display chart without loop

protected void BuildChartYear(int year)
{
    LineSeries line = new LineSeries();
    line.Name = typesFiches[0].Nom;
    System.Drawing.Color color = System.Drawing.ColorTranslator.FromHtml(GetColorTypeFiche(typesFiches[0].Valeur));
    line.Appearance.FillStyle.BackgroundColor = color;
    line.LabelsAppearance.DataFormatString = "{0}";
    line.LabelsAppearance.Position = Telerik.Web.UI.HtmlChart.LineAndScatterLabelsPosition.Above;
    line.LineAppearance.Width = 1;
    line.MarkersAppearance.MarkersType = Telerik.Web.UI.HtmlChart.MarkersType.Circle;
    line.MarkersAppearance.BackgroundColor = System.Drawing.Color.White;
    line.MarkersAppearance.Size = 8;
    line.MarkersAppearance.BorderColor = color;
    line.MarkersAppearance.BorderWidth = 2;
    line.TooltipsAppearance.DataFormatString = "{0}";

    IList<FichesDbo> fiches = DaoManager.Instance.FichesDao.GetFichesFromChantier(CurrentChantier.Id);
    for (int month = 1; month <= 12; month++)
    {
        CategorySeriesItem item = new CategorySeriesItem(fiches.Where(x => x.DateEvenement.Value.Month == month)
                .Where(y => y.DateEvenement.Value.Year == year)
                .Where(z => z.Type.Id == typesFiches[0].Id).ToList().Count, color);
        line.SeriesItems.Add(item);
    }
    line.MissingValues = Telerik.Web.UI.HtmlChart.MissingValuesBehavior.Zero;
    LineChart.PlotArea.Series.Add(line);

    LineChart.ChartTitle.Text = string.Format(Resources.MainResources.sheetsNumber + " : {0}", year.ToString());
    LineChart.DataBind();
}

If someone can tell me where is my mistake.

Thanks

Saadi
  • 2,211
  • 4
  • 21
  • 50
Romain
  • 1
  • 1

1 Answers1

0

Ok I found why it wasn't displayed. My line.Name contains an apostrophe in loop and not with the first row of my list.

Romain
  • 1
  • 1