1

I have two textboxes in which I can write numerical values which are used to get the min and max value of Y axis in a chart.

For example, if I have the values set on min = 0 and max = 100, the Y-axis of the chart will be from 0 to 100. If I change max = 50, the chart is rendered for Y-axis from 0 to 50.

The problem is if I delete the value and don't write anything in place, the chart disappears. What I want to do is if the value is deleted and nothing is written after, to keep that value and don't do anything to the chart.

This is the html:

<span class="min-max">
  Max:</br>
  <input type="number" ng-change="$ctrl.updateY()" ng-model="$ctrl.maxValue"></br>
  Min:</br>
  <input type="number" ng-change="$ctrl.updateY()" ng-model="$ctrl.minValue"></br>
</span>

This is the js function:

updateY() {
    const maxNumber = Number(this.maxValue);
    const minNumber = Number(this.minValue);
    this.lineView.chart.axis.range({max: {y: maxNumber}, min: {y: minNumber}});
}

Any suggestions?

JeffMinsungKim
  • 1,940
  • 7
  • 27
  • 50
Samurai Jack
  • 2,985
  • 8
  • 35
  • 58
  • set it to default `0`; – Guruprasad J Rao Feb 12 '18 at 10:19
  • @GuruprasadRao can you be more specific, please? anyway, this will work only for a hardcoded, initial value. if it will be written another value, let's say `max = 2341`, after I delete it I want the chart to remain the same, like Y-axis to the maximum value as 2341 – Samurai Jack Feb 12 '18 at 10:24
  • 1
    Simply check `if ( maxValue !== '' && minValue !== '' ) Draw the range`. _i am expecting angular will trim the value from input_. – Sunny Soni Feb 12 '18 at 10:26

1 Answers1

0

Since Angular has two way data binding, when the user deletes the text in the box, that has also changed the value in $scope.

You_could_ keep a copy; perhaps by using onBeforeChange() and onAfterChange().

BUT, if you say "if the text is empty, insert the previous value", then you are going to confuse & annoy a user who had deleted the current value prior to inserting a new one.

I would suggest that you ng-sho/hide a message, based on the input text being empty, that says "you can't see any chart because the X-axis value is blank".

Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551