[]
Applying a data bar to a range helps visualize each cell value relative to the other values in the same range. Use this interface to configure the appearance and behavior of a data bar rule, such as its fill, color, axis, direction, and value display.
worksheet.getRange("A1:A5").setValue(new Object[][] {
{1}, {2}, {3}, {4}, {5}
});
IDataBar dataBar = worksheet.getRange("A1:A5").getFormatConditions().addDatabar();
dataBar.setBarFillType(DataBarFillType.Solid);
dataBar.getBarColor().setColor(Color.GetGreen());
dataBar.setShowValue(false);
voiddelete()voidIConditionValue that specifies how the longest bar is evaluated for a data bar conditional format.IConditionValue that specifies how the shortest bar is evaluated for a data bar conditional format.intintintbooleanbooleantrue.getType()voidsetAppliesTo(IRange value) voidvoidsetBarFillType(DataBarFillType value) voidsetDirection(DataBarDirection value) void1 so that it is evaluated before all other rules on the worksheet.voidvoidsetPercentMax(int value) voidsetPercentMin(int value) voidsetPriority(int value) voidsetShowValue(boolean value) toJson()Use this method to retrieve the IRange associated with the current data bar rule.
worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
IRange appliesTo = dataBar.getAppliesTo();
String address = appliesTo.getAddress();
IRange to which this data bar rule is applied.Use this method to change the IRange associated with the current data bar rule.
worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
dataBar.setAppliesTo(worksheet.getRange("B1:B3"));
IRange appliesTo = dataBar.getAppliesTo();
value - The IRange to which this data bar rule is applied. Must not be null.Returns an IFormatColor object that you can use to read or modify the axis color of the data bar rule.
worksheet.getRange("A1:A3").setValue(new Object[][] {{-10}, {0}, {20}});
IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
dataBar.setAxisPosition(DataBarAxisPosition.Automatic);
IFormatColor axisColor = dataBar.getAxisColor();
axisColor.setColor(Color.GetBlue());
IFormatColor object that represents the axis color of the data bar rule.The axis position controls how positive and negative data bars are separated within each cell. Use DataBarAxisPosition.Automatic to place the axis based on the values in the range, DataBarAxisPosition.Midpoint to keep the axis centered, or DataBarAxisPosition.None to hide the axis.
worksheet.getRange("A1:A3").setValue(new Object[][] {{-10}, {0}, {20}});
IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
dataBar.setAxisPosition(DataBarAxisPosition.Automatic);
DataBarAxisPosition axisPosition = dataBar.getAxisPosition();
DataBarAxisPosition value that indicates where the data bar axis is displayed.The axis position controls how positive and negative data bars are separated within each cell. Use DataBarAxisPosition.Automatic to place the axis based on the values in the range, DataBarAxisPosition.Midpoint to keep the axis centered, or DataBarAxisPosition.None to hide the axis.
worksheet.getRange("A1:A3").setValue(new Object[][] {{-10}, {0}, {20}});
IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
dataBar.setAxisPosition(DataBarAxisPosition.Midpoint);
DataBarAxisPosition axisPosition = dataBar.getAxisPosition();
value - The DataBarAxisPosition value that specifies where the data bar axis is displayed.Use the returned IDataBarBorder object to configure the border appearance of the current data bar, such as its border type and color.
worksheet.getRange("A1:A5").setValue(new Object[][] {{1}, {2}, {3}, {4}, {5}});
IDataBar dataBar = worksheet.getRange("A1:A5").getFormatConditions().addDatabar();
IDataBarBorder border = dataBar.getBarBorder();
border.setType(DataBarBorderType.Solid);
IDataBarBorder object that specifies the border of a data bar.Returns an IFormatColor object that you can use to read or modify the fill color applied to the data bars.
worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
IFormatColor barColor = dataBar.getBarColor();
barColor.setColor(Color.GetRed());
Returns a DataBarFillType value that indicates whether the data bar uses a solid fill or a gradient fill.
worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
dataBar.setBarFillType(DataBarFillType.Gradient);
DataBarFillType fillType = dataBar.getBarFillType();
DataBarFillType value that specifies how a data bar is filled with color.Use a DataBarFillType value to specify whether the data bar uses a solid fill or a gradient fill.
worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
dataBar.setBarFillType(DataBarFillType.Gradient);
value - The data bar fill type.The returned DataBarDirection value determines whether the data bar follows the current context, is displayed from left to right, or is displayed from right to left.
worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {20}, {30}});
IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
dataBar.setDirection(DataBarDirection.RightToLeft);
DataBarDirection direction = dataBar.getDirection();
DataBarDirection value that specifies the display direction of the data bar.Use this method to control whether the data bar is rendered from left to right, from right to left, or according to the worksheet context.
worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
dataBar.setDirection(DataBarDirection.RightToLeft);
DataBarDirection direction = dataBar.getDirection();
value - The data bar direction to apply. Must be a valid DataBarDirection value.IConditionValue that specifies how the longest bar is evaluated for a data bar conditional format. Use the returned object to configure the maximum threshold for the data bar, such as a numeric limit or another supported condition value type.
worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {20}, {30}});
IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
IConditionValue maxPoint = dataBar.getMaxPoint();
maxPoint.setType(ConditionValueTypes.Number);
maxPoint.setValue(30);
IConditionValue object that specifies how the longest bar is evaluated for a data bar conditional format.IConditionValue that specifies how the shortest bar is evaluated for a data bar conditional format.Use the returned object to configure the minimum threshold for the data bar, such as a numeric limit or another supported condition value type.
worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {20}, {30}});
IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
IConditionValue minPoint = dataBar.getMinPoint();
minPoint.setType(ConditionValueTypes.Number);
minPoint.setValue(10);
IConditionValue object that specifies how the shortest bar is evaluated for a data bar conditional format.Use the returned INegativeBarFormat object to configure the fill color and border color behavior for negative values in the data bar.
worksheet.getRange("A1:A4").setValue(new Object[][] {{-10}, {-5}, {0}, {20}});
IDataBar dataBar = worksheet.getRange("A1:A4").getFormatConditions().addDatabar();
INegativeBarFormat negativeBarFormat = dataBar.getNegativeBarFormat();
negativeBarFormat.setColorType(DataBarNegativeColorType.Color);
negativeBarFormat.getColor().setColor(Color.GetRed());
INegativeBarFormat.Use this property to determine the maximum visual length applied to data bars in the conditional formatting rule.
worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
dataBar.setPercentMax(80);
int percentMax = dataBar.getPercentMax();
Use this property to control the maximum visual length of data bars in the conditional formatting rule.
worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
dataBar.setPercentMax(80);
value - The percentage of the cell width used for the longest data bar.Use this property to determine the minimum visual length applied to data bars in the conditional formatting rule.
worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
dataBar.setPercentMin(15);
int percentMin = dataBar.getPercentMin();
Use this method to control the minimum visible length of data bars in the conditional formatting rule.
worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
dataBar.setPercentMin(15);
int percentMin = dataBar.getPercentMin();
value - The length of the shortest data bar, expressed as a percentage of the cell width.The priority determines the order in which conditional formatting rules are evaluated when multiple rules exist on a worksheet. Priority values are unique within the worksheet, so changing the priority of one rule can shift the priority values of other rules.
worksheet.getRange("A1:B3").setValue(new Object[][] {{10, 5}, {30, 15}, {20, 25}});
IDataBar firstDataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
IDataBar secondDataBar = worksheet.getRange("B1:B3").getFormatConditions().addDatabar();
secondDataBar.setPriority(1);
int priority = secondDataBar.getPriority();
The priority determines the evaluation order when multiple conditional formatting rules exist on a worksheet. The value must be a positive integer between 1 and the total number of conditional formatting rules on the worksheet. Because each rule must have a unique priority, changing the priority of this rule may shift the priority values of other rules on the worksheet.
worksheet.getRange("A1:B3").setValue(new Object[][] {{10, 5}, {30, 15}, {20, 25}});
IDataBar firstDataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
IDataBar secondDataBar = worksheet.getRange("B1:B3").getFormatConditions().addDatabar();
secondDataBar.setPriority(1);
value - The priority value of the conditional formatting rule. Must be a positive integer between 1 and the total number of conditional formatting rules on the worksheet.This property indicates whether the original cell values remain visible together with the data bars.
worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
dataBar.setShowValue(false);
boolean showValue = dataBar.getShowValue();
Use this property to show or hide the original cell values while keeping the data bars visible.
worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
dataBar.setShowValue(false);
value - true to display the cell values together with the data bars; otherwise, false.true. If this property is true, lower-priority conditional formatting rules continue to be evaluated for the cells to which this data bar applies.
worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
boolean stopIfTrue = dataBar.getStopIfTrue();
For a data bar conditional formatting rule, this method returns the corresponding FormatConditionType value, such as FormatConditionType.Databar.
worksheet.getRange("A1:A5").setValue(new Object[][] {{10}, {30}, {20}, {40}, {25}});
IDataBar dataBar = worksheet.getRange("A1:A5").getFormatConditions().addDatabar();
FormatConditionType type = dataBar.getType();
After this method is called, the data bar is removed from the range to which it applies.
worksheet.getRange("A1:A5").setValue(new Object[][] {{1}, {2}, {3}, {4}, {5}});
IDataBar dataBar = worksheet.getRange("A1:A5").getFormatConditions().addDatabar();
dataBar.delete();
1 so that it is evaluated before all other rules on the worksheet. Use this method to move a data bar rule to the highest evaluation priority among the conditional formatting rules on the same worksheet.
worksheet.getRange("A1:B3").setValue(new Object[][] {{10, 5}, {30, 15}, {20, 25}});
IDataBar firstDataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
IDataBar secondDataBar = worksheet.getRange("B1:B3").getFormatConditions().addDatabar();
firstDataBar.setFirstPriority();
Use this method to move the current data bar rule to the end of the worksheet rule priority order.
worksheet.getRange("A1:B3").setValue(new Object[][] {{10, 5}, {30, 15}, {20, 25}});
IDataBar firstDataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
IDataBar secondDataBar = worksheet.getRange("B1:B3").getFormatConditions().addDatabar();
secondDataBar.setLastPriority();
This method replaces the current data bar rule with the rule defined in the specified JSON string. The JSON content is typically generated by toJson().
worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
dataBar.setBarFillType(DataBarFillType.Solid);
dataBar.getBarColor().setColor(Color.GetGreen());
dataBar.setShowValue(false);
String json = dataBar.toJson();
IDataBar copiedDataBar = worksheet.getRange("B1:B3").getFormatConditions().addDatabar();
copiedDataBar.fromJson(json);
json - The JSON string that defines a data bar conditional format.IllegalStateException - if the specified JSON string does not describe a data bar conditional format.Use this method to serialize the current data bar settings so that they can be reused with fromJson(String) or stored for later use.
worksheet.getRange("A1:A3").setValue(new Object[][] {
{10},
{30},
{20}
});
IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
String json = dataBar.toJson();