Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > How to Change the Line Weight in a the Chart Control?

Thread Tools Display Modes
Old 12-03-2010, 04:35 PM
Michael___ Michael___ is offline
Join Date: Sep 2009
Posts: 111
Default How to Change the Line Weight in a the Chart Control?

I'm using Visual basic 2010.net with service pack 4.0. I'm using the built in chart control to generate a line graph. I have a series plotted on the fastline graph. Is there a way of accessing the weight/thickness/boldness of the line and changing it? I was able ton change the colour and I could even change the point size on the fastpoint graph. This is my code for anyone who is interested, although I'm not really sure if it's relevant to my post...
Private Sub DisplayGraph_frm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Text = CustomizeGraph_frm.GraphTitle_txt.Text
        TheChart_cht.ChartAreas("ChartArea").BackColor = CustomizeGraph_frm.BackgroundColor_pnl.BackColor

        XMin = CustomizeGraph_frm.DateFrom_dtp.Value.AddHours(CustomizeGraph_frm.TimeFrom_dtp.Value.Hour).AddMinutes(CustomizeGraph_frm.TimeFrom_dtp.Value.Minute)
        XMax = CustomizeGraph_frm.DateTo_dtp.Value.AddHours(CustomizeGraph_frm.TimeTo_dtp.Value.Hour).AddMinutes(CustomizeGraph_frm.TimeTo_dtp.Value.Minute)
        XRange = DateDiff(DateInterval.Minute, XMin, XMax)
        XInterval = CustomizeGraph_frm.ReadingFrequency(CustomizeGraph_frm.ReadingFrequency_cmb.SelectedIndex)

        If CustomizeGraph_frm.ReadingFrequency_cmb.SelectedIndex >= 10 Then
            XUnit = "Minutes"
        ElseIf CustomizeGraph_frm.ReadingFrequency_cmb.SelectedIndex >= 10 And CustomizeGraph_frm.ReadingFrequency_cmb.SelectedIndex < 15 Then
            XUnit = "Days"
        ElseIf CustomizeGraph_frm.ReadingFrequency_cmb.SelectedIndex >= 15 And CustomizeGraph_frm.ReadingFrequency_cmb.SelectedIndex < 19 Then
            XUnit = "Months"
        ElseIf CustomizeGraph_frm.ReadingFrequency_cmb.SelectedIndex >= 19 Then
            XUnit = "Years"
        End If

        For i = 0 To Data.Length - 2 Step 1

            Data(i) = New Double(XRange / XInterval) {}
            For ii = 0 To XRange / XInterval Step 1
                Data(i)(ii) = RandomClass.Next(-20, 20)

            CurrentChartSeries = CustomizeGraph_frm.WaitingList_lvw.Items.Item(i).Text

            If Not CustomizeGraph_frm.WaitingList_lvw.Items.Item(i).SubItems(4).Text = "Hide Points" Then

                TheChart_cht.Series.Add(CurrentChartSeries + " Points")
                TheChart_cht.Series(CurrentChartSeries + " Points").ChartType = SeriesChartType.FastPoint
                TheChart_cht.Series(CurrentChartSeries + " Points").Color = ColorTranslator.FromHtml(CustomizeGraph_frm.WaitingList_lvw.Items.Item(i).SubItems(3).Text)

                If CustomizeGraph_frm.WaitingList_lvw.Items.Item(i).SubItems(4).Text = "Small" Then
                    TheChart_cht.Series(CurrentChartSeries + " Points").MarkerSize = 3
                ElseIf CustomizeGraph_frm.WaitingList_lvw.Items.Item(i).SubItems(4).Text = "Medium" Then
                    TheChart_cht.Series(CurrentChartSeries + " Points").MarkerSize = 4.5
                ElseIf CustomizeGraph_frm.WaitingList_lvw.Items.Item(i).SubItems(4).Text = "Large" Then
                    TheChart_cht.Series(CurrentChartSeries + " Points").MarkerSize = 6
                End If

                For ii = 0 To Data(i).Length - 1 Step 1
                    TheChart_cht.Series(CurrentChartSeries + " Points").Points.AddY(Data(i)(ii))

            End If

            TheChart_cht.Series.Add(CurrentChartSeries + " Lines")
            TheChart_cht.Series(CurrentChartSeries + " Lines").ChartType = SeriesChartType.FastLine
            TheChart_cht.Series(CurrentChartSeries + " Lines").Color = ColorTranslator.FromHtml(CustomizeGraph_frm.WaitingList_lvw.Items.Item(i).SubItems(1).Text)

            For ii = 0 To Data(i).Length - 1 Step 1
                TheChart_cht.Series(CurrentChartSeries + " Lines").Points.AddY(Data(i)(ii))

    End Sub
You don't really need to read all that. But my question still stands, is there a way to change the thickness of a line? It seems "MarkerSize" doesn't work with fastline graphs. Or if it does, I don't know what it actually does do?

Just as another thing, how would I changed the axis colour, axis weight/thickness/boldness, grid style and grid colour. I'm new to chart controls (just started today) I downloaded a file containing a load of information on how to do stuff. Unfortunately, it seems they can't get everything in their. If anyone knows of a good website that has information on Chart Control, please say. I've looked all over the place for information and there is very little. Charts probably aren't popular enough, which is a shame because it looks to me like Microsoft really went all out on them. You can have practically every chart available!
Reply With Quote
Old 12-05-2010, 06:34 AM
Michael___ Michael___ is offline
Join Date: Sep 2009
Posts: 111

As for the axis:
ChartName.ChartAreas("ChartAreaName").AxisY.LineColor = Color.Red
ChartName.ChartAreas("ChartAreaName").AxisY.LineDashStyle = ChartDashStyle.Solid
ChartName.ChartAreas("ChartAreaName").AxisY.ArrowStyle = AxisArrowStyle.None
ChartName.ChartAreas("ChartAreaName").AxisY.LineWidth = 1
There's also some other styles.

For the grid:
ChartName.ChartAreas("ChartAreaName").AxisY.MinorGrid.Enabled = True
ChartName.ChartAreas("ChartAreaName").AxisY.MinorTickMark.Enabled = True
ChartName.ChartAreas("ChartAreaName").AxisY.MajorGrid.Interval = 1
ChartName.ChartAreas("ChartAreaName").AxisY.MajorTickMark.Interval = 1
ChartName.ChartAreas("ChartAreaName").AxisY.MinorGrid.Interval = 0.5
ChartName.ChartAreas("ChartAreaName").AxisY.MinorTickMark.Interval = 0.5
ChartName.ChartAreas("ChartAreaName").AxisY.MinorGrid.LineColor = Color.Blue
ChartName.ChartAreas("ChartAreaName").AxisY.MajorTickMark.LineDashStyle = ChartDashStyle.Solid
ChartName.ChartAreas("ChartAreaName").AxisY.MajorGrid.LineWidth = 1
Then you can change the axis to the X if you wish. You can even use Y2 and X2 to specify which Y or X axis if you have multiple ones.

I was also going to uploaded a file for anyone else who may find it useful. Instead, here's the link to the download page http://code.msdn.microsoft.com/mscha...ReleaseId=4418 because when I uploaded it the file exceeded the maximum file size. It contains loads of chart control function with example code. There are no projects or examples in the form of .exe but all the code you need to create graph, charts and other forms of representing data is in there. I hope someone else finds it as useful as I did.
Reply With Quote

chart, control, line, properties, weight

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..