locked
how to change chart width RRS feed

  • Question

  • hi i am implemented one chart

    based on values on the chart i want to increase and decrease my chart width any body have any idea plz tell me????????

     


    kiran
    Wednesday, January 28, 2009 8:42 AM

Answers

  • Depends what you mean by width.

    The chart control itself is sized like any other component, by setting height and width in pixels. However, elements within the control are sized as a percentage of the width and height. So to resize a chart area to a specific height and width in pixels, you might need routines like this:

     

             private float GetRelativeWidth(int pixels)
            {
                // Convert offset in pixels to relative offset
                return 100F * (float)pixels / (float)(chart.Width);
            }

            private float GetRelativeHeight(int pixels)
            {
                // Convert offset in pixels to relative offset
                return 100F * (float)pixels / (float)(chart.Height);
            }

    You can also adjust the range of values on each axis using the Maximum and Mimimum properties.

     

    Wednesday, January 28, 2009 10:18 AM

All replies

  • use the height and width properties in runtime. 

    chart1.Width = Convert.ToInt16(txtWidth.Text);

    chart1.Height= Convert.ToInt16(txtHeight.Text);

    Wednesday, January 28, 2009 8:59 AM
  • I Want to increase chart with dynamically based on data points

     


    kiran
    Wednesday, January 28, 2009 9:12 AM
  • Depends what you mean by width.

    The chart control itself is sized like any other component, by setting height and width in pixels. However, elements within the control are sized as a percentage of the width and height. So to resize a chart area to a specific height and width in pixels, you might need routines like this:

     

             private float GetRelativeWidth(int pixels)
            {
                // Convert offset in pixels to relative offset
                return 100F * (float)pixels / (float)(chart.Width);
            }

            private float GetRelativeHeight(int pixels)
            {
                // Convert offset in pixels to relative offset
                return 100F * (float)pixels / (float)(chart.Height);
            }

    You can also adjust the range of values on each axis using the Maximum and Mimimum properties.

     

    Wednesday, January 28, 2009 10:18 AM
  • I have one chart in that when values are less chart will fine but values are more then chart is not fit to show values how to resized in coding according to values can u help me on this???

    These values are coming according the user search, so values may be less or more so according to that chart size will be less or large

     

     


    kiran
    Wednesday, January 28, 2009 10:40 AM
  • What I do is resize the chart area using those routines to convert from pixels to the "relative positioning" system that is used by elements on chart controls. You will have to work out what size you want yourself - it depends on the application. I create a RectangleF structure like this:

    float plotLeft = GetRelativeWidth(leftInPixels);

    ...  // similar code for the other values

    RectangleF plotPosition = new RectangleF(plotLeft, plotTop, plotWidth, plotHeight);

    chartArea.Position.FromRectangleF(plotPosition);


    I also set the maximum and minimum properties on both the axes, so that I can show all the data. I keep track of the max and min for each axis as I add data points to my series.

    You might get away with just the default behaviour if your series doesn't change once it is populated (I'm dealing with realtime data, so mine are constantly changing)

    Wednesday, January 28, 2009 11:02 AM