gpt4 book ai didi

asp.net - 使用 Microsoft Chart 控件在图表上添加标签

转载 作者:行者123 更新时间:2023-12-03 14:40:58 25 4
gpt4 key购买 nike

我正在使用 Microsoft Chart 控件创建 3d 图表。这是图像:

alt text
(来源:highoncoding.com)

我想在每个条形图的顶部显示点。就像条形图顶部的考试 1 一样,它应该显示 2(如 2 分)等。

这是代码:

private void BindData() {

var exams = new List<Exam>()
{
new Exam() { Name = "Exam 1", Point = 10 },
new Exam() { Name = "Exam 2", Point = 12 },
new Exam() { Name = "Exam 3", Point = 15 },
new Exam() { Name = "Exam 4", Point = 2 }
};

var series = ExamsChart.Series["ExamSeries"];



series.YValueMembers = "Point";
series.XValueMember = "Name";

//series.MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Circle;
//series.MarkerSize = 20;
//series.LegendText = "hellow";
//series.Label = "something";


var chartAreas = ExamsChart.ChartAreas["ChartArea1"];


ExamsChart.DataSource = exams;
ExamsChart.DataBind();
}

这是html代码:
<asp:Chart ID="ExamsChart" Width="600" Height="320" runat="server">
<Titles>
<asp:Title Text="Exam Report" />
</Titles>
<Series>
<asp:Series Name="ExamSeries" ChartType="Column">
</asp:Series>
</Series>
<ChartAreas>

<asp:ChartArea Name="ChartArea1">
<Area3DStyle Enable3D="true" WallWidth="10" />
</asp:ChartArea>
</ChartAreas>
</asp:Chart>

更新:

这是答案:
 foreach (var exam in exams) {

var point = new DataPoint();
point.SetValueXY(exam.Name, exam.Point);

point.Label = exam.Name;

series.Points.Add(point);
}

最佳答案

直接来自 MS 图表示例:

// Show data points values as labels
chart1.Series["Series1"].IsValueShownAsLabel = true;

// Set data point label
chart1.Series["Series1"].Points[2].Label = "My Point Label\nLabel Line #2";

关于asp.net - 使用 Microsoft Chart 控件在图表上添加标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2685370/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com