How to customize background and foreground settings in chart?
The chart background image can be set either at run-time or at design time.The chart area background image can be changed using the ChartAreaBackImage Property. We can also set any solid color as the backcolor of the chart control as well as ChartArea.
The font face of the text can be chosen from any one of the system supported font faces using the Font property of the ChartStyleInfo class.The font style of the series text can be changed by selecting any one of the different font styles using the FontStyle property of the ChartFontInfo class.
C#
// Settting Image to the Chart
ofd.InitialDirectory = @"..\..\Images";
ofd.Filter = "BackGround files (*.jpg)|*.jpg|All files (*.*)|*.*";
if(DialogResult.OK == ofd.ShowDialog())
{
filename = ofd.FileName;
this.chartControl1.ChartAreaBackImage = new Bitmap(filename);
}
// Setting Chart Background Color
this.chartControl1.ChartInterior = Color.Red;
// Changing font for chart axis
ChartAxis axis = this.chartControl1.PrimaryXAxis;
axis.Font = new Font(Font_Name, 10f, (FontStyle)Enum.Parse(typeof(FontStyle), this.cmb_FontStyle.SelectedItem.ToString(), true));
axis = this.chartControl1.PrimaryYAxis;
VB
' Settting Image to the Chart
Dim ofd As OpenFileDialog = New OpenFileDialog()
ofd.InitialDirectory = "..\..\Images"
ofd.Filter = "BackGround files (*.jpg)|*.jpg|All files (*.*)|*.*"
If DialogResult.OK = ofd.ShowDialog() Then
filename = ofd.FileName
Me.chartControl1.ChartAreaBackImage = New Bitmap(filename)
End If
'Setting BackGroundColor
Me.chartControl1.ChartInterior = Color.Red
' Changing Font for chart axis
Dim axis As ChartAxis = Me.chartControl1.PrimaryXAxis
axis.Font = New System.Drawing.Font(Font_Name, 10.0F, Me.chartControl1.PrimaryXAxis.Font.Style)
axis = Me.chartControl1.PrimaryYAxis