c# - Scale Y-Axis of a Chart depending on the Values within a section of X-Values for several Series -


i have got aplication this: chart scaling x-axis textboxes below chart user can set min , max of x-axis of chart. code it:

private void textboxxaxismin_textchanged(object sender, eventargs e) {     double x;     //checks if input double , smaller max value     //if (double.tryparse(this.textboxxaxismin.text, out x) && x < chart1.chartareas[0].axisx.maximum)         if (double.tryparse(this.textboxxaxismin.text, out x))     {         this.textboxxaxismin.backcolor = color.white;         chart1.chartareas[0].axisx.minimum = convert.todouble(this.textboxxaxismin.text);         //changeyscalamin(chartcharacteristiccurvesthermoelemts, convert.todouble(this.textboxcharacteristiccurvesthermoelementxmin.text), convert.todouble(this.textboxcharacteristiccurvesthermoelementxmax.text));               //method scale y axis      }     else         //if textbox not highlighted          this.textboxxaxismin.backcolor = color.orange;     //calls max function update chart if max-value valid      double y;     //checks if input double , greater min value     if (double.tryparse(this.textboxxaxismax.text, out y) && y > chart1.chartareas[0].axisx.minimum)     {         this.textboxxaxismax.backcolor = color.white;         chart1.chartareas[0].axisx.maximum = convert.todouble(this.textboxxaxismax.text);           //method scale y axis      }     else         //if textbox not  highlighted          this.textboxxaxismax.backcolor = color.orange; } 

now have y-axis scaled automatically. y-min should calulated min value of series in section of (x-min , x-max) , y-max maximum of series in selected section. problem implementation.

in example, y-min should changed 50.

i hosted hole exampleproject here @ githup.

this scale y-axis minimum , maximum values between minimum , maximum values[0] of x-axis series 0 1:

double max = double.minvalue;  double min = double.maxvalue;   double leftlimit  = chart1.chartareas[0].axisx.minimum; double rightlimit = chart1.chartareas[0].axisx.maximum;  (int s = 0; s <= 1; s++) {     foreach (datapoint dp in chart1.series[s].points)     {         if (dp.xvalue >= leftlimit && dp.xvalue <= rightlimit)         {             min = math.min(min, dp.yvalues[0]);             max = math.max(max, dp.yvalues[0]);         }     } }  chart1.chartareas[0].axisy.maximum = max; chart1.chartareas[0].axisy.minimum = min; 

edit: while testing noticed resetting min&max values not quite obvious. here how:

chart1.chartareas[0].axisy.minimum = double.nan; chart1.chartareas[0].axisy.maximum = double.nan; chart1.chartareas[0].axisx.minimum = double.nan; chart1.chartareas[0].axisx.maximum = double.nan; 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -