سؤال

I created a series of a graph in C# windows forms with the Chart control, but I need to change the font and color of the data series via code.

I'm adding a data serie at runtime like this:

     this.Chart_PlanComp.Series.Add("Qtde_Componente");
هل كانت مفيدة؟

المحلول 2

You can set the color like this:

var serie = Chart_PlanComp.Series.Add("Qtde_Componente");
serie.Color = Color.Green;

Though, setting the font doesn't seem to work...

var serie = Chart_PlanComp.Series.Add("Qtde_Componente");
serie.Font = new Font("Courier New", 15.0f, FontStyle.Italic); //changes nothing

Not even if you set it before adding:

var series = new System.Windows.Forms.DataVisualization.Charting.Series();
series.Font = new Font("Courier New", 15.0f, FontStyle.Italic);
this.chart1.Series.Add(series);
//still nothing

نصائح أخرى

System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
series1.Font = new System.Drawing.Font("Trebuchet MS", 9F);
series1.LabelForeColor = Color.AliceBlue;
this.Chart_PlanComp.Series.Add(series1);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top