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. how can i improve these code's display efficient?

how can i improve these code's display efficient?

Scheduled Pinned Locked Moved C#
questioncssgraphicstutorialcode-review
10 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
    smallkubi
    wrote on last edited by
    #1

    hi,all: This question has been bothering me for a long time. I have some series in chart1, for exampe,i have 100 series, each series have 1 point(or more). And i need paint a rectangle when mouse move, so i have code as follows, but when i run it, the rectangle can not move it smoothly, it is so slow . And i found if series number is less than 10, it maybe move fast. how can i solve it,i have no idea. public Form1() { InitializeComponent(); Series series1; for (int i = 0; i < 100; i++) { series1 = new Series(); series1.Points.Add(new DataPoint(i, i)); //Just for example series1.IsVisibleInLegend = false; chart1.Series.Add(series1); } } bool _isdown = false; Rectangle r=new Rectangle(); private void chart1_MouseDown(object sender, MouseEventArgs e) { _isdown = true; } private void chart1_MouseMove(object sender, MouseEventArgs e) { if (_isdown) { r.Width = 100; r.X = e.X; r.Y = e.Y; r.Height = 100; panel1.Invalidate(); } } private void chart1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Pen p = new Pen(Color.LightBlue); p.Width = 2; p.Color = Color.Red; g.DrawRectangle(p, r); }

    D 1 Reply Last reply
    0
    • S smallkubi

      hi,all: This question has been bothering me for a long time. I have some series in chart1, for exampe,i have 100 series, each series have 1 point(or more). And i need paint a rectangle when mouse move, so i have code as follows, but when i run it, the rectangle can not move it smoothly, it is so slow . And i found if series number is less than 10, it maybe move fast. how can i solve it,i have no idea. public Form1() { InitializeComponent(); Series series1; for (int i = 0; i < 100; i++) { series1 = new Series(); series1.Points.Add(new DataPoint(i, i)); //Just for example series1.IsVisibleInLegend = false; chart1.Series.Add(series1); } } bool _isdown = false; Rectangle r=new Rectangle(); private void chart1_MouseDown(object sender, MouseEventArgs e) { _isdown = true; } private void chart1_MouseMove(object sender, MouseEventArgs e) { if (_isdown) { r.Width = 100; r.X = e.X; r.Y = e.Y; r.Height = 100; panel1.Invalidate(); } } private void chart1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Pen p = new Pen(Color.LightBlue); p.Width = 2; p.Color = Color.Red; g.DrawRectangle(p, r); }

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      First, your code leaks resources at an insane rate. Every time the Paint event is called you're creating a new Pen and not Disposing it. This will eventually cause Windows to crash. Create the Pen once, outside the event handler and reuse it. Dispose it when your application closes. Next, this runs slow because you're drawing 100 series on a chart! It wasn't really designed to do that and isn't optimized to handle that kind of a load. Every time you move the mouse with the button down, the chart has to be redrawn to "unpaint" the rectangle that your painting and redraw the rectangle in its new position and dimensions. To make it worse, you only have one data point per series! The more points you add to search series the exponentially slower the painting will become. The only solution you have is to not draw so many chart series.

      A guide to posting questions on CodeProject

      Click this: Asking questions is a skill. Seriously, do it.
      Dave Kreskowiak

      S 1 Reply Last reply
      0
      • D Dave Kreskowiak

        First, your code leaks resources at an insane rate. Every time the Paint event is called you're creating a new Pen and not Disposing it. This will eventually cause Windows to crash. Create the Pen once, outside the event handler and reuse it. Dispose it when your application closes. Next, this runs slow because you're drawing 100 series on a chart! It wasn't really designed to do that and isn't optimized to handle that kind of a load. Every time you move the mouse with the button down, the chart has to be redrawn to "unpaint" the rectangle that your painting and redraw the rectangle in its new position and dimensions. To make it worse, you only have one data point per series! The more points you add to search series the exponentially slower the painting will become. The only solution you have is to not draw so many chart series.

        A guide to posting questions on CodeProject

        Click this: Asking questions is a skill. Seriously, do it.
        Dave Kreskowiak

        S Offline
        S Offline
        smallkubi
        wrote on last edited by
        #3

        actually ,i need plot 20 series with 400 points, but when i plot them in the chartarea, it's also slow when mouse move. But if i put 20*400 points in one series, the mouse move is fast. But my requirement is 20 line-series, so i don't want one series's end point line to the other's begin point.

        D 1 Reply Last reply
        0
        • S smallkubi

          actually ,i need plot 20 series with 400 points, but when i plot them in the chartarea, it's also slow when mouse move. But if i put 20*400 points in one series, the mouse move is fast. But my requirement is 20 line-series, so i don't want one series's end point line to the other's begin point.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          The only way to speed things up is to reduce the number of points you have to draw in the graph. 20 * 400 = 8000 points. Now, the question is why are you drawing boxes on the chart?

          A guide to posting questions on CodeProject

          Click this: Asking questions is a skill. Seriously, do it.
          Dave Kreskowiak

          S 2 Replies Last reply
          0
          • D Dave Kreskowiak

            The only way to speed things up is to reduce the number of points you have to draw in the graph. 20 * 400 = 8000 points. Now, the question is why are you drawing boxes on the chart?

            A guide to posting questions on CodeProject

            Click this: Asking questions is a skill. Seriously, do it.
            Dave Kreskowiak

            S Offline
            S Offline
            smallkubi
            wrote on last edited by
            #5

            oh,i need to meet ZoomIn function. When user is doing ZoomIn, he can see his mouse's trace through a various width and heigh rectangle when mouse is down.

            1 Reply Last reply
            0
            • D Dave Kreskowiak

              The only way to speed things up is to reduce the number of points you have to draw in the graph. 20 * 400 = 8000 points. Now, the question is why are you drawing boxes on the chart?

              A guide to posting questions on CodeProject

              Click this: Asking questions is a skill. Seriously, do it.
              Dave Kreskowiak

              S Offline
              S Offline
              smallkubi
              wrote on last edited by
              #6

              When i plot in the chart, i found chart speed is slower than other soft. Now i think chartarea refresh is cost most of time, but some times i don't need to refresh background series, just need to use invalidate to call paint function. So is there any method to stop backgound series refresh ,not refresh paint function content?

              D 1 Reply Last reply
              0
              • S smallkubi

                When i plot in the chart, i found chart speed is slower than other soft. Now i think chartarea refresh is cost most of time, but some times i don't need to refresh background series, just need to use invalidate to call paint function. So is there any method to stop backgound series refresh ,not refresh paint function content?

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                No, there isn't, and YES, you HAVE TO PAINT THE BACKGROUND, which means painting the entire chart area. It's the only way to "undo" the previous painting of your rectangle so it can be repainted with it's new coordinates and size.

                A guide to posting questions on CodeProject

                Click this: Asking questions is a skill. Seriously, do it.
                Dave Kreskowiak

                S 1 Reply Last reply
                0
                • D Dave Kreskowiak

                  No, there isn't, and YES, you HAVE TO PAINT THE BACKGROUND, which means painting the entire chart area. It's the only way to "undo" the previous painting of your rectangle so it can be repainted with it's new coordinates and size.

                  A guide to posting questions on CodeProject

                  Click this: Asking questions is a skill. Seriously, do it.
                  Dave Kreskowiak

                  S Offline
                  S Offline
                  smallkubi
                  wrote on last edited by
                  #8

                  oh, but why some other soft can work so fast? Maybe other language can good work for this?

                  D 1 Reply Last reply
                  0
                  • S smallkubi

                    oh, but why some other soft can work so fast? Maybe other language can good work for this?

                    D Offline
                    D Offline
                    Dave Kreskowiak
                    wrote on last edited by
                    #9

                    The language used doesn't matter at all. What does matter is the design of your graphing component, which you didn't write. You're trying to adapt a graphing component that isn't designed to do the job you want to do. If you make your own graphing component that also supports drawing boxes on it and is OPTIMIZED to support what you want to do, then you can get the speed out of it.

                    A guide to posting questions on CodeProject

                    Click this: Asking questions is a skill. Seriously, do it.
                    Dave Kreskowiak

                    S 1 Reply Last reply
                    0
                    • D Dave Kreskowiak

                      The language used doesn't matter at all. What does matter is the design of your graphing component, which you didn't write. You're trying to adapt a graphing component that isn't designed to do the job you want to do. If you make your own graphing component that also supports drawing boxes on it and is OPTIMIZED to support what you want to do, then you can get the speed out of it.

                      A guide to posting questions on CodeProject

                      Click this: Asking questions is a skill. Seriously, do it.
                      Dave Kreskowiak

                      S Offline
                      S Offline
                      smallkubi
                      wrote on last edited by
                      #10

                      ok,i got it. Thank you

                      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