ASP.NET图表控件数值标签位置

3
我正在使用asp.net图表控件展示数据,使用了3D柱状图。我将值显示在柱子旁边(seriesCount.IsValueShownAsLabel = true;)。但是图表控件仍然将值标签渲染在柱子上方,这使得值难以阅读。我试图将该标签定位到右侧,但目前为止我还没有找到方法实现。我也尝试启用智能标签并在柱子上放置标记来推开值,但并不成功。任何建议都会受到赞赏。
示例代码:
Chart chartSubjects = new Chart();
chartSubjects.Width = Unit.Pixel(800);
chartSubjects.Height = Unit.Pixel(300);
chartSubjects.AntiAliasing = AntiAliasingStyles.All;

Series seriesCount = new Series("subjectsCountSeries");
seriesCount.YValueType = ChartValueType.Int32;
seriesCount.ChartType = SeriesChartType.Bar;
seriesCount.IsValueShownAsLabel = true;
seriesCount.ChartArea = "subjectsCountArea";
chartSubjects.Series.Add(seriesCount);

ChartArea areaCount = new ChartArea("subjectsCountArea");
LabelStyle yAxisStyle = new LabelStyle();
yAxisStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml("#444444");
yAxisStyle.Font = new System.Drawing.Font("Arial", 11, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
areaCount.AxisY.LabelStyle = yAxisStyle;
areaCount.AxisY.IsLabelAutoFit = false;
areaCount.Position.Width = 50;
areaCount.Position.Height = 100;
areaCount.Position.X = 0;
areaCount.Position.Y = 0;
areaCount.Area3DStyle.Enable3D = true;
areaCount.Area3DStyle.LightStyle = LightStyle.Realistic;
areaCount.Area3DStyle.WallWidth = 4;
areaCount.Area3DStyle.Inclination = 10;
areaCount.Area3DStyle.Perspective = 10;
areaCount.Area3DStyle.Rotation = 20;
areaCount.Area3DStyle.PointDepth = 90;
chartSubjects.ChartAreas.Add(areaCount);

int[] pointsToAdd = new int[] { 1434, 712, 601, 204, 173, 168, 64, 35, 22, 8, 2 };
foreach (int point in pointsToAdd)
{
    DataPoint dataPoint = new DataPoint();
    dataPoint.SetValueY(point);
    seriesCount.Points.Add(dataPoint);
}

enter image description here


请贴上一些代码,以说明你遇到的问题。 - Steve Wellens
seriesCount.MarkerColor = System.Drawing.Color.Transparent; seriesCount.MarkerSize = 16; seriesCount.MarkerStyle = MarkerStyle.Square; seriesCount.SmartLabelStyle.MinMovingDistance = 10; seriesCount.SmartLabelStyle.AllowOutsidePlotArea = LabelOutsidePlotAreaStyle.Yes; seriesCount.SmartLabelStyle.Enabled = true; seriesCount.SmartLabelStyle.MovingDirection = LabelAlignmentStyles.Right; - SynBiotik
之前的代码是我尝试解决问题的第一次尝试。最终我意识到我缺少了一个关键的代码片段:seriesCount.SmartLabelStyle.IsMarkerOverlappingAllowed = false; 这有效地将值标签推向了右侧,除了第一个柱形图(从透明标记向左推)。 - SynBiotik
2个回答

3
这是你在寻找的内容吗?
<asp:Series Name="Series1" ChartType="Bar" 
            CustomProperties="BarLabelStyle=Right" IsValueShownAsLabel="True" 
            Palette="EarthTones" XValueMember="xvalue" YValueMembers="yvalue">
</asp:Series>

"

CustomProperties="BarLabelStyle=Right"对我来说很有用。

"
该代码段对我很有用。

0

在你的情况下,我会使用:

chartSubjects.Series["seriesCount"]["LabelStyle"] = "Right";

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接