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
  1. Home
  2. General Programming
  3. C#
  4. Create chart

Create chart

Scheduled Pinned Locked Moved C#
2 Posts 2 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.
  • S Offline
    S Offline
    shamsteady
    wrote on last edited by
    #1

    I'm doing this coding and its running properly. This coding is to create a chart that can be drag and drop. I create the Panel as the bar. The panel will be generated depend on input. But the problem is the Panel is generated too many as it like there is nonstop loop. Can anyone solve this problem...plz using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; namespace CMSMS { public class mypanel:System.Windows.Forms.Panel { private bool isDragging=false; public int x,y; protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown (e); isDragging = true; x = e.X; y = e.Y; } protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp (e); isDragging = false; } protected override void OnMouseMove(MouseEventArgs e) { if (isDragging == true) { this.Left= e.X + this.Left - x; this.Top = e.Y + this.Top - y; } } } } using System; using System.Drawing; using System.Drawing.Imaging; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace CMSMS { /// /// Summary description for GranttChart. /// public class GranttChart : System.Windows.Forms.Form { ... private mypanel [] bar = new mypanel[60]; ... public void GenerateGranttChart() { GenerateChart(); } private void GenerateChart() { for (int i = 0; i < 10; i++) { int xPosition = 100; for (index = 0; index < 10; index++) { for (int j = 0; j < 10; j++) { DrawPanel( xPosition, yPosition,j,brush, length); xPosition += length; } yPosition -= range; } } } private void DrawPanel(int X,int Y,int j,SolidBrush brush, int l) { bar[j]=new mypanel(); this.bar[j].Size = new Size(l,20); this.bar[j].BackColor = brush.Color; this.bar[j].Location = new Point(X,Y); } rotected override void OnPaint(PaintEventArgs e) { ... GenerateChart(); ... }

    P 1 Reply Last reply
    0
    • S shamsteady

      I'm doing this coding and its running properly. This coding is to create a chart that can be drag and drop. I create the Panel as the bar. The panel will be generated depend on input. But the problem is the Panel is generated too many as it like there is nonstop loop. Can anyone solve this problem...plz using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; namespace CMSMS { public class mypanel:System.Windows.Forms.Panel { private bool isDragging=false; public int x,y; protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown (e); isDragging = true; x = e.X; y = e.Y; } protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp (e); isDragging = false; } protected override void OnMouseMove(MouseEventArgs e) { if (isDragging == true) { this.Left= e.X + this.Left - x; this.Top = e.Y + this.Top - y; } } } } using System; using System.Drawing; using System.Drawing.Imaging; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace CMSMS { /// /// Summary description for GranttChart. /// public class GranttChart : System.Windows.Forms.Form { ... private mypanel [] bar = new mypanel[60]; ... public void GenerateGranttChart() { GenerateChart(); } private void GenerateChart() { for (int i = 0; i < 10; i++) { int xPosition = 100; for (index = 0; index < 10; index++) { for (int j = 0; j < 10; j++) { DrawPanel( xPosition, yPosition,j,brush, length); xPosition += length; } yPosition -= range; } } } private void DrawPanel(int X,int Y,int j,SolidBrush brush, int l) { bar[j]=new mypanel(); this.bar[j].Size = new Size(l,20); this.bar[j].BackColor = brush.Color; this.bar[j].Location = new Point(X,Y); } rotected override void OnPaint(PaintEventArgs e) { ... GenerateChart(); ... }

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      First thing that I see is that you have 1000 iterations of DrawPanel. You have three nested loops, so you get the following logic:

      for each iteration of the outermost loop
      for each iteration of the next loop
      for each iteration of the inner loop
      DrawPanel
      end for
      end for
      end for

      BTW - you have declared an array with a fixed size of 60, so you will get an overflow. You would be much better off declaring this as List<mypanel> bar = new List<mypanel> and then using this instead. -- modified at 8:00 Friday 16th March, 2007

      Deja View - the feeling that you've seen this post before.

      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