locked
How can I make my chart background look like this ? RRS feed

  • Question

  • I love the theme that this ms chart is using.

     

    http://blogs.msdn.com/blogfiles/alexgor/WindowsLiveWriter/DataBindingMSChartcontrol_10712/image_thumb.png

     

    could someone tell me all the settings I need to set the border color, the border width, the back color, the gradient style, and the themes to make it look exactly like that for my line chart?

     

    this would be much appreciated thanks

    Friday, November 12, 2010 9:19 AM

Answers

  • Try this (or just copy the lines starting from "'Chart properties"):

    Imports System.Windows.Forms.DataVisualization.Charting
    Imports System.Drawing
    
    Public Class Form1
    
    	Private Sub ExampleForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
    		'Add a chart in the designer
    
    		'To remove the automatically added default series
    		Chart1.Series.Clear()
    
    		'Add sample data
    		Dim data As DataTable = getData()
    		Me.Chart1.DataBindCrossTable(data.AsEnumerable, "Product", "Name", "Amount", Nothing)
    
    		'Chart properties
    		Me.Chart1.Width = 400
    		Me.Chart1.Height = 300
    		Me.Chart1.BackColor = Color.FromArgb(211, 223, 240)
    		Me.Chart1.BackGradientStyle = GradientStyle.TopBottom
    		Me.Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss
    		Me.Chart1.BorderlineColor = Color.FromArgb(26, 59, 105)
    		Me.Chart1.BorderlineDashStyle = ChartDashStyle.Solid
    		Me.Chart1.BorderlineWidth = 2
    
    		'Chart area properties
    		Me.Chart1.ChartAreas(0).BackColor = Color.FromArgb(64, 165, 191, 228)
    		Me.Chart1.ChartAreas(0).BackGradientStyle = GradientStyle.TopBottom
    		Me.Chart1.ChartAreas(0).BackSecondaryColor = Color.Transparent
    		Me.Chart1.ChartAreas(0).AxisX.IsLabelAutoFit = False
    		Me.Chart1.ChartAreas(0).AxisX.LabelStyle.Font = New Font("Trebuchet MS", 8.25F, FontStyle.Bold)
    		Me.Chart1.ChartAreas(0).AxisX.LineColor = Color.FromArgb(64, 64, 64, 64)
    		Me.Chart1.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.FromArgb(64, 64, 64, 64)
    		Me.Chart1.ChartAreas(0).AxisY.IsLabelAutoFit = False
    		Me.Chart1.ChartAreas(0).AxisY.LabelStyle.Font = New Font("Trebuchet MS", 8.25F, FontStyle.Bold)
    		Me.Chart1.ChartAreas(0).AxisY.LineColor = Color.FromArgb(64, 64, 64, 64)
    		Me.Chart1.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.FromArgb(64, 64, 64, 64)
    
    		'Legend properties
    		Me.Chart1.Legends(0).Docking = Docking.Top
    		Me.Chart1.Legends(0).Alignment = StringAlignment.Center
    		Me.Chart1.Legends(0).Font = New Font("Trebuchet MS", 8.25F, FontStyle.Bold)
    		Me.Chart1.Legends(0).BackColor = Color.Transparent
    
    		'Series properties
    		For Each s As Series In Chart1.Series
    			s("DrawingStyle") = "LightToDark"
    		Next
    
    	End Sub
    
    	Private Function getData() As DataTable
    
    		Dim data As New DataTable
    
    		data.Columns.Add("Name", GetType(String))
    		data.Columns.Add("Product", GetType(String))
    		data.Columns.Add("Amount", GetType(Integer))
    
    		data.Rows.Add("Andrew", "Prod A", 35)
    		data.Rows.Add("Andrew", "Prod B", 65)
    		data.Rows.Add("Andrew", "Prod C", 65)
    		data.Rows.Add("Andrew", "Prod D", 72)
    		data.Rows.Add("Andrew", "Prod E", 43)
    		data.Rows.Add("Andrew", "Other", 7)
    
    		data.Rows.Add("David", "Prod A", 45)
    		data.Rows.Add("David", "Prod B", 41)
    		data.Rows.Add("David", "Prod C", 76)
    		data.Rows.Add("David", "Prod D", 33)
    		data.Rows.Add("David", "Prod E", 71)
    		data.Rows.Add("David", "Other", 32)
    
    		data.Rows.Add("Bryan", "Prod A", 63)
    		data.Rows.Add("Bryan", "Prod B", 17)
    		data.Rows.Add("Bryan", "Prod C", 53)
    		data.Rows.Add("Bryan", "Prod D", 27)
    		data.Rows.Add("Bryan", "Prod E", 24)
    		data.Rows.Add("Bryan", "Other", 67)
    
    		Return data
    
    	End Function
    
    End Class
    

    Most of this is copied from the source code of the Samples Environment. There are similar looking examples there.

    Friday, November 12, 2010 12:13 PM
    Moderator

All replies

  • Try this (or just copy the lines starting from "'Chart properties"):

    Imports System.Windows.Forms.DataVisualization.Charting
    Imports System.Drawing
    
    Public Class Form1
    
    	Private Sub ExampleForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
    		'Add a chart in the designer
    
    		'To remove the automatically added default series
    		Chart1.Series.Clear()
    
    		'Add sample data
    		Dim data As DataTable = getData()
    		Me.Chart1.DataBindCrossTable(data.AsEnumerable, "Product", "Name", "Amount", Nothing)
    
    		'Chart properties
    		Me.Chart1.Width = 400
    		Me.Chart1.Height = 300
    		Me.Chart1.BackColor = Color.FromArgb(211, 223, 240)
    		Me.Chart1.BackGradientStyle = GradientStyle.TopBottom
    		Me.Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss
    		Me.Chart1.BorderlineColor = Color.FromArgb(26, 59, 105)
    		Me.Chart1.BorderlineDashStyle = ChartDashStyle.Solid
    		Me.Chart1.BorderlineWidth = 2
    
    		'Chart area properties
    		Me.Chart1.ChartAreas(0).BackColor = Color.FromArgb(64, 165, 191, 228)
    		Me.Chart1.ChartAreas(0).BackGradientStyle = GradientStyle.TopBottom
    		Me.Chart1.ChartAreas(0).BackSecondaryColor = Color.Transparent
    		Me.Chart1.ChartAreas(0).AxisX.IsLabelAutoFit = False
    		Me.Chart1.ChartAreas(0).AxisX.LabelStyle.Font = New Font("Trebuchet MS", 8.25F, FontStyle.Bold)
    		Me.Chart1.ChartAreas(0).AxisX.LineColor = Color.FromArgb(64, 64, 64, 64)
    		Me.Chart1.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.FromArgb(64, 64, 64, 64)
    		Me.Chart1.ChartAreas(0).AxisY.IsLabelAutoFit = False
    		Me.Chart1.ChartAreas(0).AxisY.LabelStyle.Font = New Font("Trebuchet MS", 8.25F, FontStyle.Bold)
    		Me.Chart1.ChartAreas(0).AxisY.LineColor = Color.FromArgb(64, 64, 64, 64)
    		Me.Chart1.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.FromArgb(64, 64, 64, 64)
    
    		'Legend properties
    		Me.Chart1.Legends(0).Docking = Docking.Top
    		Me.Chart1.Legends(0).Alignment = StringAlignment.Center
    		Me.Chart1.Legends(0).Font = New Font("Trebuchet MS", 8.25F, FontStyle.Bold)
    		Me.Chart1.Legends(0).BackColor = Color.Transparent
    
    		'Series properties
    		For Each s As Series In Chart1.Series
    			s("DrawingStyle") = "LightToDark"
    		Next
    
    	End Sub
    
    	Private Function getData() As DataTable
    
    		Dim data As New DataTable
    
    		data.Columns.Add("Name", GetType(String))
    		data.Columns.Add("Product", GetType(String))
    		data.Columns.Add("Amount", GetType(Integer))
    
    		data.Rows.Add("Andrew", "Prod A", 35)
    		data.Rows.Add("Andrew", "Prod B", 65)
    		data.Rows.Add("Andrew", "Prod C", 65)
    		data.Rows.Add("Andrew", "Prod D", 72)
    		data.Rows.Add("Andrew", "Prod E", 43)
    		data.Rows.Add("Andrew", "Other", 7)
    
    		data.Rows.Add("David", "Prod A", 45)
    		data.Rows.Add("David", "Prod B", 41)
    		data.Rows.Add("David", "Prod C", 76)
    		data.Rows.Add("David", "Prod D", 33)
    		data.Rows.Add("David", "Prod E", 71)
    		data.Rows.Add("David", "Other", 32)
    
    		data.Rows.Add("Bryan", "Prod A", 63)
    		data.Rows.Add("Bryan", "Prod B", 17)
    		data.Rows.Add("Bryan", "Prod C", 53)
    		data.Rows.Add("Bryan", "Prod D", 27)
    		data.Rows.Add("Bryan", "Prod E", 24)
    		data.Rows.Add("Bryan", "Other", 67)
    
    		Return data
    
    	End Function
    
    End Class
    

    Most of this is copied from the source code of the Samples Environment. There are similar looking examples there.

    Friday, November 12, 2010 12:13 PM
    Moderator
  • you are a life saver.  it works. thanks

     

    I can not use the samples environment in VS 2005.  When I downloaded VS2008 express edition, it too also said it can not load it due to compatibility reasons.  So thats why I had to turn to this forum.

     

    Thanks once again!!

    Friday, November 12, 2010 6:48 PM
  • you are a life saver.  it works. thanks

     

    I can not use the samples environment in VS 2005.  When I downloaded VS2008 express edition, it too also said it can not load it due to compatibility reasons.  So thats why I had to turn to this forum.

     

    Thanks once again!!


    When someone answers your question, please mark it as the answer.

    Thanks!


    Ed Price a.k.a User Ed, Microsoft Experience Program Manager (Blog, Twitter, Wiki)
    Saturday, January 21, 2012 3:15 AM