我的RadHtmlChart有问题。这很容易理解,当我使用foreach循环以编程方式添加LineSeries时,我的图表(标题,轴,轴名称......)不会显示但是显示没有,我不明白为什么。
这是我的asp.net代码
<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#代码隐藏,它不显示带循环的图表
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();
}
和C#代码隐藏,显示没有循环的图表
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();
}
如果有人能告诉我我的错误在哪里。
由于
答案 0 :(得分:0)
好的,我发现为什么它没有显示出来。我的line.Name在循环中包含一个撇号,而不是我列表的第一行。