我是一名仍在学习 C# 的学生,但遇到了问题。我正在尝试制作一个包含 7 个不同字段和 7 个不同图例的图形(饼图)。
我有这个代码:
private void InitializeChart()
{
this.components = new System.ComponentModel.Container();
ChartArea chartArea1 = new ChartArea();
Legend legend1 = new Legend()
{ BackColor = Color.FromArgb(97,97,97), //achtergrondkleur legende
ForeColor = Color.White, //kleur van tekst in legende
Title = "Legende grafiek", //titel legende
TitleForeColor = Color.White}; //kleur titel legende
pieChart = new Chart();
((ISupportInitialize)(pieChart)).BeginInit();
SuspendLayout();
//===Pie chart
chartArea1.Name = "PieChartArea";
pieChart.ChartAreas.Add(chartArea1);
pieChart.Height = 300;
pieChart.Width = 300;
pieChart.Dock = System.Windows.Forms.DockStyle.Fill;
legend1.Name = "Legend1";
pieChart.Legends.Add(legend1);
pieChart.Location = new System.Drawing.Point(0, 50);
//====Bar Chart
chartArea1 = new ChartArea();
chartArea1.Name = "BarChartArea";
AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Load += new EventHandler(StatistiekenForm_Load);
((ISupportInitialize)(this.pieChart)).EndInit();
this.ResumeLayout(false);
}
private void LoadPieChart()
{
pieChart.Series.Clear();
pieChart.Width = 300;
pieChart.Height = 300;
pieChart.Palette = ChartColorPalette.Excel;
pieChart.BackColor = Color.Transparent;
//pieChart.Titles.Add("Overzicht uitgaven");
pieChart.ChartAreas[0].BackColor = Color.Transparent;
Series series = new Series
{
Name = "Overzicht",
IsVisibleInLegend = true,
Color = System.Drawing.Color.FromArgb(97,97,97),
ChartType = SeriesChartType.Pie
};
pieChart.Series.Add(series);
int teller, prijsje = 50;
for (teller = 0; teller < 7; teller++)
{
series.Points.Add(teller);
var p1 = series.Points[teller];
p1.AxisLabel = Convert.ToString(prijsje + "€");
p1.LegendText = Convert.ToString("legende " + teller);
prijsje += 50;
}
pieChart.Invalidate();
panelPie.Width = 400;
panelPie.Height = 400;
panelPie.Controls.Add(pieChart);
}
谁能解释一下为什么我一直看到六片,但传说中显示的是七片?您可以在此图像中看到问题:http: //i.imgur.com/4xciNUG.png ?1
非常感谢,Yenthe。