mirror of https://github.com/grafana/grafana.git
				
				
				
			Graph: support setting field units (#26529)
This commit is contained in:
		
							parent
							
								
									43ef052d57
								
							
						
					
					
						commit
						ad5f1c953b
					
				| 
						 | 
					@ -13,7 +13,10 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <div ng-if="yaxis.show">
 | 
					    <div ng-if="yaxis.show">
 | 
				
			||||||
      <div class="gf-form gf-form--grow">
 | 
					      <div class="gf-form gf-form--grow">
 | 
				
			||||||
        <label class="gf-form-label width-6">Unit</label>
 | 
					        <label class="gf-form-label width-6">
 | 
				
			||||||
 | 
					          Unit
 | 
				
			||||||
 | 
									  <info-popover mode="right-normal">The default unit used when not defined by the datasource or in the Fields or Overrides configuration.</info-popover>
 | 
				
			||||||
 | 
					        </label>
 | 
				
			||||||
        <unit-picker onChange="ctrl.setUnitFormat(yaxis)" value="yaxis.format" class="flex-grow-1" />
 | 
					        <unit-picker onChange="ctrl.setUnitFormat(yaxis)" value="yaxis.format" class="flex-grow-1" />
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -305,6 +305,7 @@ export class GraphCtrl extends MetricsPanelCtrl {
 | 
				
			||||||
    for (const series of this.seriesList) {
 | 
					    for (const series of this.seriesList) {
 | 
				
			||||||
      series.applySeriesOverrides(this.panel.seriesOverrides);
 | 
					      series.applySeriesOverrides(this.panel.seriesOverrides);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // Always use the configured field unit
 | 
				
			||||||
      if (series.unit) {
 | 
					      if (series.unit) {
 | 
				
			||||||
        this.panel.yaxes[series.yaxis - 1].format = series.unit;
 | 
					        this.panel.yaxes[series.yaxis - 1].format = series.unit;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
| 
						 | 
					@ -378,6 +379,7 @@ export const plugin = new PanelPlugin<GraphPanelOptions, GraphFieldConfig>(null)
 | 
				
			||||||
  .useFieldConfig({
 | 
					  .useFieldConfig({
 | 
				
			||||||
    standardOptions: [
 | 
					    standardOptions: [
 | 
				
			||||||
      FieldConfigProperty.DisplayName,
 | 
					      FieldConfigProperty.DisplayName,
 | 
				
			||||||
 | 
					      FieldConfigProperty.Unit,
 | 
				
			||||||
      FieldConfigProperty.Links, // previously saved as dataLinks on options
 | 
					      FieldConfigProperty.Links, // previously saved as dataLinks on options
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue