Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. ZedGraph and dynamic data

ZedGraph and dynamic data

Scheduled Pinned Locked Moved C#
csharpdatabasegraphicsdata-structuresasp-net
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Genbox
    wrote on last edited by
    #1

    Hi. I tried asking this question in ZedGraph article, but I got no answer. I have a database with some data that I would like to be represented in graphs. The database is like this: exercise | weight | maxweight squat | 100 | 120 deadlift | 120 | 130 rows | 50 | 20 <- edit: the spaces may not show correctly -> I would like to represent the values from each exercise in graphs. but i have no idea how to do that. - i'm using the "bar-graph" from ZedGraph. I would also like the graph to be dynamic, so that if a user inserts a new exercise, then the graph will extend with another graph. this is what i have currently: private void OnRenderGraph(System.Drawing.Graphics g, ZedGraph.MasterPane mPane) { GraphPane pane = mPane[0]; pane.Title = "Training"; pane.YAxis.Title = "Exercise"; pane.XAxis.Title = "Weight (kg)"; SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); SqlDataReader rdr = null; conn.Open(); SqlCommand cmd = new SqlCommand("SELECT exercise FROM training WHERE userid='"+ Page.Request.Params["userid"] +"'", conn); rdr = cmd.ExecuteReader(); rdr.Read(); double[] x = { 50, 30, 50 }; BarItem myCurve = pane.AddBar("Weight", x, null, Color.DarkGreen); myCurve.Bar.Fill = new Fill(Color.DarkGreen, Color.LightGreen, Color.DarkGreen, 90f); string[] labels = { rdr["exercise"].ToString() }; pane.YAxis.TextLabels = labels; rdr.Close(); conn.Close(); // Draw the Y tics between the labels instead of at the labels pane.YAxis.IsTicsBetweenLabels = true; // Set the YAxis to Text type pane.YAxis.Type = AxisType.Text; // Set the bar type to stack, which stacks the bars by automatically accumulating the values pane.BarType = BarType.Stack; // Make the bars horizontal by setting the BarBase to "Y" pane.BarBase = BarBase.Y; pane.AxisChange(g); } I am very new to C# and asp.net. I know that i should put the rdr.Close() and conn.Close() into an exception with the rest of the sql connection, but i'm still testing.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups