1

I have a chart and a ChartArea inside of it.

I want to resize the ChartArea on the Y axis or on the X axis, but I can't do it. I need a ChartArea control element which can be resized with the mouse at runtime.

I need resizing element on the chart (or ChartArea) which resizes my ChartArea..

Cœur
  • 37,241
  • 25
  • 195
  • 267
Bezgodov
  • 11
  • 1
  • 7
  • 2
    Possible duplicate of [How to modify C# Chart control chartArea percentages](http://stackoverflow.com/questions/15423080/how-to-modify-c-sharp-chart-control-chartarea-percentages) – Praveen Vinny Nov 29 '16 at 03:35
  • @PraveenVinny i think, no. I tried that article, but it didn't help me – Bezgodov Nov 29 '16 at 03:52
  • Please explain just what you want to achieve. It is certainly possible but atm I would know what to do as I don't understand just what you want. Why resize the ChartArea which by default is sized to have maximum size while still leaving room for the surrounding element like Title, Legend Labels etc..??? – TaW Nov 29 '16 at 10:11

1 Answers1

1

Here is an example that..

  • ..adds a moveable HorizontalLineAnnotation as a handle and..
  • ..codes the AnnotationPositionChanging to use the handle as a slider between two ChartAreas:

enter image description here

Define at class level:

HorizontalLineAnnotation slider =   new HorizontalLineAnnotation();

Set it up and add to Chart:

slider.AllowMoving = true;
slider.LineWidth = 2;
slider.LineColor = Color.DarkSlateGray;
slider.X = 0;     
slider.Y = 50;
slider.Width = 100;
chart1.Annotations.Add(slider);

This set the slider to the left at the middle and lets it go across the whole chart.

private void chart1_AnnotationPositionChanging(object sender,
                                               AnnotationPositionChangingEventArgs e)
{
    if (e.Annotation == slider)
    {
        chart1.ChartAreas[0].Position.Height = (float)slider.Y - 4;
        chart1.ChartAreas[1].Position.Height = (float)(100f - slider.Y) - 4;
        chart1.ChartAreas[1].Position.Y = (float)slider.Y;

        chart1.Update();
    }
}

This resizes the two ChartAreas, keeping 4% slack for outside stuff. I you have a Title, a top-docked Legend or large Labels you need to give more than the 4%...

Of course you can modify it to change the size of only one ChartArea as well, although I don't see why you would want that..

TaW
  • 53,122
  • 8
  • 69
  • 111