EPPlus: Customizing clustered bar chart data label text - epplus

I have created a clustered bar chart with EPPlus as shown here:
I would like to customize each bar label to include the percentage, as pictured here:
How can I customize the label? I didn't see any ability to do this via the DataLabel.
Here is the code used to create the data and chart:
var startCell = worksheet.Cells[1, 1];
startCell.Offset(0, 0).Value = "Theme";
startCell.Offset(0, 1).Value = "Count";
startCell.Offset(0, 2).Value = "%";
startCell.Offset(1, 0).Value = "Working Remotely";
startCell.Offset(1, 1).Value = 53;
startCell.Offset(1, 2).Value = 0.11;
startCell.Offset(2, 0).Value = "Collaboration";
startCell.Offset(2, 1).Value = 42;
startCell.Offset(2, 2).Value = 0.05;
worksheet.Cells[FromRow: 2, FromCol: 3, ToRow: 3, ToCol: 3].Style.Numberformat.Format = "0%";
worksheet.Cells[FromRow: 1, FromCol: 1, ToRow: 3, ToCol: 3].AutoFitColumns();
var barChart = (ExcelBarChart) worksheet.Drawings.AddChart("ThemeBarChart", eChartType.BarClustered);
barChart.SetPosition(4, 0, 0, 0);
barChart.SetSize(500, 150);
barChart.Series.Add(worksheet.Cells[FromRow: 2, FromCol: 2, ToRow: 3, ToCol: 2], worksheet.Cells[FromRow: 2, FromCol: 1, ToRow: 3, ToCol: 1]);
barChart.Legend.Remove();
var xAxis = barChart.XAxis;
xAxis.MajorTickMark = eAxisTickMark.None;
xAxis.MinorTickMark = eAxisTickMark.None;
xAxis.Fill.Style = eFillStyle.NoFill;
var yAxis = barChart.YAxis;
yAxis.Deleted = true;
yAxis.RemoveGridlines();
var dataLabel = barChart.Series[0].DataLabel;
dataLabel.Position = eLabelPosition.OutEnd;
dataLabel.ShowValue = true;

Related

vba listbox to show background color for header

I want to show different background color to row 1 in listback. I am using below code to color but it is changing entire background for all listbox rows. Please help if there is anyway to color first row of listbox.
UserForm4.ListBox15.BackColor = RGB(0, 0, 255)
If lv_item = 0 Then
UserForm4.ListBox15.AddItem "Sr no" 'Additem creates a new row
UserForm4.ListBox15.List(lv_item, 1) = "Volumn Processed"
UserForm4.ListBox15.List(lv_item, 2) = "Volumn Target"
UserForm4.ListBox15.List(lv_item, 3) = "Approached"
UserForm4.ListBox15.List(lv_item, 4) = "Confidence Level"
End If
lv_item = 1
With rs
rs.MoveFirst
While Not rs.EOF
UserForm4.ListBox15.AddItem rs.Fields("Sr no").Value 'Additem creates a new row
UserForm4.ListBox15.List(lv_item, 1) = rs.Fields("Volumn Processed").Value
UserForm4.ListBox15.List(lv_item, 2) = rs.Fields("Volumn Target").Value
UserForm4.ListBox15.List(lv_item, 3) = rs.Fields("Approached").Value
UserForm4.ListBox15.List(lv_item, 4) = rs.Fields("Confidence Level").Value
UserForm4.ListBox15.List(lv_item, 6) = rs.Fields("Unique ID").Value

Add linetype to geom_segment legend

Aim: add the linetypes of the segments to the legend, as well as the colour.
Problem: only the colour is showing.
Data:
m = as.data.frame(matrix(c(1:10), ncol = 2, nrow = 10))
Plot:
ggplot(m, aes(v1,v2)) + geom_segment(aes(x = 0, xend = 9.75, y = 10, yend = 10, colour = "PEL"), linetype = "dotted") + geom_segment(aes(x = 0, xend = 9.75, y = 5, yend = 5, colour = "AL1"), linetype = "longdash") + geom_segment(aes(x = 0, xend = 9.75, y = 2, yend = 2, colour = "ISQG"), linetype = "solid") + scale_colour_manual("legend", values = c("PEL" = "black", "AL1" = "blue", "ISQG" = "purple"), guide = guide_legend(override.aes = list(alpha = 1))) + theme(legend.position = "bottom")
I've tried adding scale_linetype_manual(values = c("PEL" = "dotted", "AL1" = "longdash", "ISQG" = "solid") but nothing changes.
This answer is similar, Legend linetype in ggplot but I couldn't figure out how to make it work with geom_segment
Thank you in advance
The most ggplot-esque way of doing this, is to include a linetype variable as part of mapping in the aes() functions. You must then ensure that both the linetype and colour scales have the same titles, breaks, limits, labels etc.
Alternatively, you can also include the linetype in the override.aes part of guide_legend().
library(ggplot2)
ggplot() +
geom_segment(
aes(x = 0, xend = 9.75, y = 10, yend = 10, colour = "PEL", linetype ="PEL"),
) +
geom_segment(
aes(x = 0, xend = 9.75, y = 5, yend = 5, colour = "AL1", linetype ="AL1"),
) +
geom_segment(
aes(x = 0, xend = 9.75, y = 2, yend = 2, colour = "ISQG", linetype = "ISQG"),
) +
scale_colour_manual(
"legend",
values = c("PEL" = "black", "AL1" = "blue", "ISQG" = "purple"),
) +
scale_linetype_manual(
"legend",
values = c("PEL" = "dotted", "AL1" = "longdash", "ISQG" = "solid"),
) +
theme(legend.position = "bottom")
Created on 2022-05-19 by the reprex package (v2.0.1)

The second description of the x-axis in ggplot2?

I am wondering if there is a way to add the second description of x-axis in ggplot2 as follows: Here "the second description" refers "Sample A / Sample B / two arrows" colored in red (shown in the figure).
Please click for the figure!
Of course, I can just put the "second description" using PowerPoint as I did, but I just wonder if it is possible to add it using ggplot2.
Here is the code for the background plot.
library(ggplot2)
library(ggridges)
x <- data.frame(v1=rnorm(100, mean = -2, sd = 0.022),
v2=rnorm(100, mean = -1, sd = 0.022),
v3=rnorm(100, mean = 0, sd = 0.022),
v4=rnorm(100, mean = 1, sd = 0.022),
v5=rnorm(100, mean = 2, sd = 0.022),
v6=rnorm(100, mean = 3, sd = 0.022),
v7=rnorm(100, mean = 4, sd = 0.022))
colnames(x) <- c("A",
"B",
"C",
"D",
"E",
"F",
"G")
head(x)
# Manipulate the data
library(reshape2)
data <- melt(x)
head(data)
# Generating plot
colors <- rainbow(7)
ggplot(data, aes(x = value, y = variable)) +
geom_density_ridges(aes(fill = variable), alpha=0.6, bandwidth=0.1) +
scale_fill_manual(values = colors)+
theme(axis.title = element_text(size = 12),
axis.text = element_text(size = 10),
legend.text = element_text(size = 12),
plot.title = element_text(size = 17, face = "bold",
margin = margin(b=10), hjust = 0.5),
panel.spacing = unit(0.1, "lines"),
legend.position="none") +
geom_vline(xintercept = 0, linetype="dotted") +
geom_vline(xintercept = 2, linetype="dotted",
color = "red", size=1.2) +
xlab("") +
ylab("Groups") +
labs(title = 'Density plot of each group')
Thank you in advance!
I'm not 100% sure this is what you mean, but you can add text on the x-axis using the following in labs:
labs(x="← Sample A Sample B →")
I got the arrows from unicode here: http://xahlee.info/comp/unicode_arrows.html
There are bigger arrows in the link if needed.
EDIT:
Here's your code adapted with the new labels in red font:
ggplot(data, aes(x = value, y = variable)) +
geom_density_ridges(aes(fill = variable), alpha=0.6, bandwidth=0.1) +
scale_fill_manual(values = colors)+
theme(axis.title = element_text(size = 12),
axis.text = element_text(size = 10),
legend.text = element_text(size = 12),
plot.title = element_text(size = 17, face = "bold",
margin = margin(b=10), hjust = 0.5),
panel.spacing = unit(0.1, "lines"),
legend.position="none") +
geom_vline(xintercept = 0, linetype="dotted") +
geom_vline(xintercept = 2, linetype="dotted",
color = "red", size=1.2) +
xlab("🢀 Sample A Sample B 🢂") +
theme(axis.title.x = element_text(size=40,colour = "red")) +
ylab("Groups") +
labs(title = 'Density plot of each group')
You can also push the labels further apart by adding extra spaces. Bring them closer together with fewer spaces.

VBA USER FORM error 6 work around

I currently have a bunch of Combo boxes that has a option for Yes, No or N/A
Then I Have a Command button that that runs a calculation then moves to the next page
Private Sub CommandButton2_Click()
Dim a As Long, b As Long
a = IIf(Cbx1_1.Value = "Yes", 1, 0) + IIf(Cbx1_2.Value = "Yes", 1, 0) +_
IIf(Cbx1_3.Value = "Yes", 1, 0) + IIf(Cbx1_4.Value = "Yes", 1, 0)
b = 4 - IIf(Cbx1_1.Value = "N/A", 1, 0) - IIf(Cbx1_2.Value = "N/A", 1, 0)_
- IIf(Cbx1_3.Value = "N/A", 1, 0) - IIf(Cbx1_4.Value = "N/A", 1, 0)
OUTBX1.Text = Format(a / b, "00.00%")
MultiPage1.Value = 1
End Sub
Now the Only Problem that I am experiencing now is that if all the boxes are check as "N/A" then I get the 0/0 problem (Error 6 : Overflow)
I know that with Excel I would have used an ERRORIF formula to solve this. Is there a way that I can tell VBA that if:
=ERRORIF (b=0) then MultiPage1.Value = 1 else
OUTBX1.Text = Format(a / b, "00.00%")
Thank you to everyone for you help the final answer to this is coded as following:
Private Sub CommandButton2_Click()
Dim a As Long, b As Long
a = IIf(Cbx1_1.Value = "Yes", 1, 0) + IIf(Cbx1_2.Value = "Yes", 1, 0) + IIf(Cbx1_3.Value = "Yes", 1, 0) + IIf(Cbx1_4.Value = "Yes", 1, 0)
b = 4 - IIf(Cbx1_1.Value = "N/A", 1, 0) - IIf(Cbx1_2.Value = "N/A", 1, 0) - IIf(Cbx1_3.Value = "N/A", 1, 0) - IIf(Cbx1_4.Value = "N/A", 1, 0)
If b = 0 Then
MultiPage1.Value = 1
Else
OUTBX1.Text = Format(a / b, "00.00%")
MultiPage1.Value = 1
End If
End Sub

Export to excel functionality on JQuery dialoge buttons - MVC4

I have a Jquery dialoge box which contains 4 buttons . Export to excel is one of them.
I am trying to export my grid data to excel . Please let me know if you have any similar examples.
Please let me know , how should i write and call export to excel on jquery dialog button click.
To write something to excel file:
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
object misValue = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Excel.Workbook workBook = excelApp.Workbooks.Add(misValue);
Microsoft.Office.Interop.Excel.Worksheet workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets.get_Item(1);
Microsoft.Office.Interop.Excel.Range range;
//top of document
workSheet.Cells[1, 1] = string.Format("{0:dd.MM.yyyy}", DateTime.Now);
workSheet.Cells[1, 6] = "Something1";
workSheet.Cells[2, 3] = "Something2";
workSheet.Cells[4, 3] = "Something3";
workSheet.Cells[6, 3] = "Something4";
// test content
for (int i = 0; i < 10; i++)
{
workSheet.Cells[i + 9, 1] = (i + 1).ToString();
workSheet.Cells[i + 9, 2] = i.ToString();
workSheet.Cells[i + 9, 3] = Math.Round(2.555, 2);
workSheet.Cells[i + 9, 4] = "Hi";
workSheet.Cells[i + 9, 5] = i.ToString();
workSheet.Cells[i + 9, 6] = i.ToString();
}
//show document
excelApp.Visible = true;
When "Export to excell" button clicks, call a action that contains above code.