我正在使用Telerik RadChart绘制折线图。一切都很好,除了零值不显示为附加。
是否存在导致此行为的外观属性?
我正在创建这样的控件:
/// <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;
}
我正在添加这样的值:
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);
答案 0 :(得分:0)
如果有人遇到同样的问题:
我最终使用了一个调整后的值(所以如果值为0,我使用0.001),所以它实际上渲染了点(或者我的情况下为Bar),然后使用我自己的字符串属性作为标签的值。
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%"); }
}
对于BarSeries绑定:
<telerik:BarSeries Name="My value" Stacked="false" DataFieldY="AjustedValue">
<Appearance>
<FillStyle BackgroundColor="#92b622"></FillStyle>
</Appearance>
<LabelsAppearance ClientTemplate='#=dataItem.StringValue#' Position="OutsideEnd">
</LabelsAppearance>
</telerik:BarSeries>