Solved Series Line colors

Posted on 2014-08-07
Last Modified: 2014-08-07
I generate the following chart using the code below it. How do I change the line colors and legend line colors
Also I want to slant the dates at the bottom at a 45 degree angle. Is that possible?

Sub oChart_Actualv_Budget(ByVal oConnectionString As String, ByVal oSQL As String, ByVal oFilter As String)

            'First build GridView 
            Dim oGridView As New GridView
            Dim dt As DataTable = SQL_Data_Table.GetSQLDataTable(oConnectionString, oSQL)
            If oFilter <> "" Then
                dt.DefaultView.RowFilter = oFilter
            End If
            oGridView.DataSource = dt
            oGridView.Visible = False

            ' Initialize the Chart object    
            Dim chart1 As New Chart()
            chart1.ID = "chart1"

            'Add to do code here
            If Not IsPostBack Then
                ' Initialize objects and elements
                Dim chartArea1 As New ChartArea()
                Dim legend1 As New Legend()
                Dim series1 As New Series()
                Dim series2 As New Series()
                Dim series3 As New Series()

                ' Set the Chart Properties
                chart1.Width = 1200
                'chart1.Height = 340

                chart1.Palette = ChartColorPalette.Light
                chart1.BackColor = System.Drawing.Color.Gray
                chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss

                chart1.BorderlineColor = System.Drawing.Color.Gray
                'chart1.BorderLineStyle = ChartDashStyle.Solid
                chart1.BorderlineWidth = 4
                chart1.BackGradientStyle = GradientStyle.LeftRight

                ' Set the ChartArea properties
                chartArea1.Name = "Default"
                chartArea1.BackColor = System.Drawing.Color.Gray
                chartArea1.BackGradientStyle = GradientStyle.LeftRight
                chart1.BorderSkin.SkinStyle = BorderSkinStyle.Raised

                chart1.BackColor = Drawing.Color.Navy
                chartArea1.BackColor = Drawing.Color.DarkRed

                ' Add the ChartArea to the Chart

                chartArea1.AxisX.LabelStyle.Enabled = True
                chartArea1.AxisX.IsLabelAutoFit = True
                chartArea1.AxisX.LabelAutoFitStyle = LabelAutoFitStyles.LabelsAngleStep30

                ' Set the Legend properties
                legend1.Name = "Default"
                legend1.Docking = Docking.Bottom
                legend1.LegendStyle = LegendStyle.Row
                legend1.Alignment = System.Drawing.StringAlignment.Center

                legend1.BackColor = System.Drawing.Color.Transparent
                legend1.BorderColor = System.Drawing.Color.Black
                legend1.BorderWidth = 1

                ' Add the Legend to the Chart

                ' Set the Series properties
                'series1.BorderColor = System.Drawing.Color.DarkSlateGray
                series1.Name = "Actual"
                series1.ChartType = SeriesChartType.Line
                series1.BorderColor = Drawing.Color.Black
                series1.BorderWidth = 4

                'series2.BorderColor = System.Drawing.Color.DarkSlateGray
                series2.Name = "Budget"
                series2.ChartType = SeriesChartType.Line
                series1.BorderWidth = 4

                'series3.Name = "Series3"
                'series3.BorderWidth = 3
                'series3.ChartType = SeriesChartType.Line

                ' Add the Series to the Chart
                chartArea1.AxisX.Interval = 1
                'chartArea1.AxisX.LabelStyle.IsEndLabelVisible = False

                Dim strDate As String
                Dim y As Decimal
                For i As Integer = 0 To oGridView.Rows.Count - 1
                    strDate = CStr(CDate(oGridView.Rows(i).Cells(2).Text))
                    y = CDec(oGridView.Rows(i).Cells(3).Text)
                    series1.Points.AddXY(strDate, y)

                For i As Integer = 0 To oGridView.Rows.Count - 1
                    strDate = CStr(CDate(oGridView.Rows(i).Cells(2).Text))
                    y = CDec(oGridView.Rows(i).Cells(4).Text)
                    series2.Points.AddXY(strDate, y)

                'Preserve the chart's state during callbacks
                'chart1.CallbackStateContent = CallbackStateContent.All
            End If

            ' You MUST add the Chart to a form. By default, form1 is created on aspx pages.
        Catch ex As Exception
        End Try

    End Sub

Open in new window

Question by:murbro
    LVL 35

    Accepted Solution

    In my initial post on your previous question I forgot to adjust BorderColor to Color (after changing the chart type to line) but in the second post I did. So (on line 80) you can use:
    series1.Color = Drawing.Color.Black

    Open in new window

    to set the line color and this will also change the color in the legend.

    Note that you seem to have a copy/paste error on line 86, should be series2 I guess?

    For the slanted labels use an angle of positive or negative 45 depending if you want to slant up or down:
    chartArea1.AxisX.LabelStyle.Angle = -45

    Open in new window


    Author Closing Comment

    Great. Thanks very much

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now