VB programming

posted by .

This problem is creating code for a line chart.

- Write a program to create the line chart. Use Table in 9.6:

Table 9.6] Two -year college enrollments (in thousands).

1960 1970 1980 1990 2000
Male 283 1375 2047 2233 2398
Female 170 945 2479 3007 3358

This is my code: It works but it does not draw the Line with dots. I can't figure it out. Could you help me figure it out? Please

Public Class frmLineChart

Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
Dim quantity() As String = {283, 1375, 2047, 2233, 2398, _
170, 945, 2479, 3007, 3358}
Dim gr As Graphics = picBox.CreateGraphics
Dim strVar As String = "Male"
gr.DrawString(strVar, Me.Font, Brushes.Green, 50, 75)
gr.DrawString("Female", Me.Font, Brushes.Orange, 165, 5)
'The picture box has width 210 and height 150
gr.DrawLine(Pens.Black, 40, 110, picBox.Width, 110) 'Draw x-axis
gr.DrawLine(Pens.Black, 40, 110, 40, 1) 'Draw y-axis
gr.DrawLine(Pens.Green, 60, 105, 365, -80) 'Draw tick mark
gr.DrawLine(Pens.Orange, 65, 105, 330, -75) 'Draw tick marks
gr.DrawString("3358", Me.Font, Brushes.Black, 10, 5)

For i As Integer = 0 To quantity.GetUpperBound(0)
gr.DrawLines(Pens.Green, 1199 + i * 40, _
(110 - quantity(i) / 2), 20, quantity(i) / 2)

gr.DrawString("1960 1970 1980 1990 2000", Me.Font, _
Brushes.Black, 50, 115)
gr.DrawString("Two-year college enrollments (in thousands).", Me.Font, _
Brushes.Black, 40, 135)

End Sub
End Class

  • VB programming -

    Not sure if you have the latest version of code, because it doesn't compile.
    Inside of the for-loop, you have DrawLines instead of DrawLine, and the calculations have to be cast as integers.

    Once that's done, the axes seem to show properly, which means that you understand how the DrawLine function works.

    Then you need to calculate the starting and end points of each line segment, not forgetting that for a line chart, the end-point of one segment is the beginning of another segment. Right now, the lines are not joining each other.
    Also, the size of the picBox is probably left to default. Since you are "hardcoding" the axes, you may want to define the size of the picBox inside the sub-program using picBox.width=.... etc.

    Give it another try. You're not far.

  • VB programming -

    Okay, I understand what you've advised somewhat, but was wondering if you can give a simple example of the line segments. I kind of based this off of a bar chart I created. Thanks..

  • VB programming -

    maximum value called

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. Algebra

    These data represent the population of a certain city. Year Population(in thousands) 1950 18 1960 23 1970 29 1980 32 1990 38 2000 42 Use the line graph to predict the population in the year 2010 I recommend graphing the points, draw …
  2. Geometry

    Recal a graph, chart, or table that you used in previous courses to help present data more effectively. How did you create the graph, chart, or table?
  3. Alegebra II

    Money_Word_Problems: In 1950, the average price of a car was about $2000. This may sound inexpensive but the average income in 1950 was much less than it is now. To compare dollar amounts over time, use the formula V=A/S(C), where …
  4. Math

    The per capita public debt (in thousands of dollars) of the United States for the years 1940 to 1990 appears below. Create a scatterplot and determine a trend line. Based on your scatterplot, what do you expect the per capita public …
  5. Math 115 wk7

    Recall a graph, chart, or table that you used in previous courses to help present data more effectively. How did you create the graph, chart, or table?
  6. Math

    The table below gives the educational attainment of the U.S. population 25 years and older since 1960. Males- Percentage with 4 years of highschool 1960 39.5% 1970 51.9% 1980 67.3% 1990 77.7% 2000 84.2% 2004 84.8% Percentage with 4 …
  7. calculus

    I solved this problem, can someone check it to make sure I did it right. There are two parts to this intrepation and estimate of the value. Let C(t) be the total value of the US currency (coins and banknotes) in circulation at time, …
  8. algebra

    How do I predict an item's price at a future date (what formula do I use?
  9. Algebra

    Use the coordinates of the two points that show male life expectancies for 1980 and 2000 to write a linear function that models life expectancy. E (x), for men born in this community x years after 1960 Coordinates are 1960-66.8 1970-67.5 …
  10. Math

    Calculate the percent of change of the hamburgers price each decade, and use your results to determine the average rate of change from 1960–2000. 1960 1970 1980 1990 2000 $0.15 $0.30 $0.50 $0.75 $0.89

More Similar Questions