I am trying to create a single bold DataLabel on a chart using SpreadsheetGear. I can set the number to be Green using the code below:
DataLabels(0).NumberFormat = "[Green]###,###,##0"
But when I attempt to set a property of the Font nothing appears to happen. I have tried the below with no success.
DataLabels(0).Font.Bold = True
The code you have should work. If you have other code that is manipulating the series that the data labels belong to, try putting the line
DataLabels(0).Font.Bold = True
after any such code.
Related
I want all cells of a Google sheet to be formatted identically (same font, same font size, same wrapping, same alignment). However, even if I select the whole sheet and set all formatting values, every time I enter a new value in an empty cell (sometimes copy-pasted from web pages, sometimes typed), the 'preset' formatting specs seem to have been lost and I must respecify them. Does someone know of a way to make the preformatting stick?
Copying and pasting the usual way brings with it the formatting of the source as best as Sheets can manage. Instead of using "Paste" or Ctrl-V, use "Paste Special" (Ctrl-Alt-V). A small clipboard icon will appear to the lower right of the on-screen paste area. Click it and choose "Paste values only."
This must be done even if you paste from one sheet within Google Sheets to another. If you just paste the regular way, it not only brings in the formatting of the source sheet, it breaks up any existing conditional formatting ranges you have in place.
Try using CTRL+SHIFT+V to paste. Doing so will only paste the copied value to the sheet without affecting the formatting.
Potential workaround:
With Apps Script you can run a simple onEdit() trigger to run every time an edit is made on the sheet. So you could use this to run a script that changes the format of cells every time an edit is made.
This would involve getting the whole data range and getting the rich text values of each cell, making a copy of the rich text value object and modifying it with the RichTextValueBuilder. This is turn involves copying and modifying the TextStyle with the TextStyleBuilder.
The wrapping and alignment are set on the whole range with setWrap(isWrapEnabled) and setHorizontalAlignment(alignment).
Example
function onEdit() {
// initialize main variables
let file = SpreadsheetApp.getActive();
let sheet = file.getSheetByName("Sheet1"); // change to your sheet name
let range = sheet.getDataRange();
// This sets the whole range wrap and alignment
range.setWrap(true);
range.setHorizontalAlignment("center")
// Get the rich text values in a 2D array
let richTextValues = range.getRichTextValues();
// Two map functions to return the modified 2D array.
let newRichTextValues = richTextValues.map(row => {
return row.map(cell => {
// Gets the text style from the richText value
let style = cell.getTextStyle()
// Copy the text style and set the bold, font and size
let styleCopy = style.copy()
.setBold(true)
.setFontFamily("Comfortaa")
.setFontSize(11)
.build();
// Set the new rich text value
let newRichTextValues = cell.copy()
.setTextStyle(styleCopy)
.build();
return newRichTextValue
})
})
// Set the whole range to the rich text value.
range.setRichTextValues(newRichTextValues)
}
This should work as-is by copying this into the script editor, trying to run it once from there to get the authorizations done, and then editing your sheet. Remember to add in your sheet name.
Demonstration
This is what it looks like in action:
In this example, I used
Text wrapping as on.
Center alignment
Bold text
"Comfortaa" font
11 font size
You should change these attributes to the ones that you want. There are other attributes available to customize too.
As you can see, it could get a bit tricky if you need to exclude certain ranges, but this is absolutely possible depending on your exact use case.
It should also be mentioned that this is quite an inefficient approach, as it gets the whole range and updates everything. Ideally you want to identify the exact changes and update those, but again, this depends on your exact use case. To get the range that was modified with an onEdit trigger you can use the Event object.
References
simple onEdit() trigger
RichTextValue
RichTextValueBuilder
TextStyle
TextStyleBuilder
setHorizontalAlignment(alignment)
setWrap(isWrapEnabled)
Event object
I'm trying to create an expandable label that looks like the one in the picture:
I have two problems:
How do I make the label truncate the tail such that it leaves enough place for the More button/clickable text?
How do I place the More text?
Maybe, I am going about it the wrong way? Instead of playing with the number of lines, should I maybe try to calculate how much text goes into one and a half line and present it only, and then when clicking More I present the whole text?
Would appreciate any advice, thanks!
You can use this library to achieve your expected output.
https://github.com/apploft/ExpandableLabel
Specify the number of lines you want to display default.
expandableLabel.numberOfLines = 2
Set true if the label should be collapsed or false for expanded.
expandableLabel.collapsed = true
collapsedAttributedLink
Set the link name that is shown when collapsed.
expandableLabel.collapsedAttributedLink = NSAttributedString(string: "More")
expandedAttributedLink
Set the link name that is shown when expanded. It is optional and can be nil.
expandableLabel.expandedAttributedLink = NSAttributedString(string: "Less")
I'm using in my app the TextFields component of Google's Material Components library.
As you can see in the following screenshot, the text input is way too close of the leadingView. How can I add some margin between them?
Here's the code I'm using to create this text field:
emailTextField.translatesAutoresizingMaskIntoConstraints = false
emailTextField.delegate = self
emailTextField.leadingView = UIImageView(image: UIImage(named: "MailIcon"))
emailTextField.leadingViewMode = .always
emailTextFieldController = MDCTextInputControllerUnderline(textInput: emailTextField)
emailTextFieldController?.placeholderText = "Email"
The underline style text field is not a recommended design anymore. And the original design didn't specify a padding constant for the leading view. Consider changing to the filled controller which has been shown to perform much better in user research studies.
If you have to stick with underline, getting your desired layout is pretty easy.
Make sure you're on the latest version of MaterialComponents. This could mean you need to run pod update MaterialComponents if you're using CocoaPods.
Subclass MDCTextInputControllerUnderline.
Override the property leadingViewTrailingPaddingConstant and return whatever padding you'd like. In Objective-C, this would look like:
- (CGFloat)leadingViewTrailingPaddingConstant {
return 16.f;
}
Set your text fields to use the new class you've made.
Incidentally, we just pushed the ability to change the clear button's color easily. You can set it to match the underline and text by setting the property textInputClearButtonTintColor.
I use a MaterialDesignIcon in a label like this:
Label info = new Label("Label", MaterialDesignIcon.AC_UNIT.graphic("-fx-fill: red;"));
I don't know what CSS is supports (https://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html) but I thought it was Text. -fx-underline worked and so did -fx-font-size. I understand that other font properties don't always work because the font doesn't support them, so that's fine. None of the Shape properties worked so the above fill doesn't do anything.
I only see the colors change by the Swatch but I want something local. What CSS properties are supported and how can I change a single icon's color?
MaterialDesignIcon.graphic() creates an instance of Label. So to change its color you can use fx-text-fill: red.
To inspect your GUI you can use ScenicView
I have a highstock graph with flags that initially is correctly set.
See on Figure 1:
The graph's data is loaded dynamically when the vertical scroll bar is changed. The only thing that changes is the series data with the function
function afterSetExtremes(e) {
var new_data_to_be_loaded = getNewDataToBeLoaded();
chart.series[0].setData(new_data_to_be_loaded);
}
The new series data is loaded correctly but the flags is incorreclty re-arranged, se the Figure 2:
So what's wrong on the setting, since the chart.series[0].setData just set the series not the previous flags added?
Almost a solution:
I found that setdata(data, false), setting the animation/redraw to false solve the problem of wrong flag positioning.
Take a look at that: http://jsfiddle.net/b6b63nwy/10/
But this did raise another problem: the series tooltip does not appear anymore. Is this a highstocks bug?
The answer:
http://forum.highcharts.com/highstock-usage/bug-series-tooltip-doesn-t-render-when-use-series-setdata-t37593/
=====================================================================
If you take a look at the Series.setData section in the official API, you will find that the second argument is a Boolean property which tells if redraw the chart. Instead of setData, try to use Series.update() function.
API Reference:
http://api.highcharts.com/highcharts/Series.setData
http://api.highcharts.com/highstock/Series.update