MS Chart Control: Change the order of series in a legend - mschart

How do I change the order of series in a legend?
My Line series is appearing before my StackedColumn series, but after my Column series.
Chart c = new Chart();
ChartArea ca = c.ChartAreas.Add("main");
Legend lg = c.Legends.Add("mainLegend");
Series s1 = c.Series.Add("s1");
s1.ChartType = ChartType.StackedColumn;
Series s2 = c.Series.Add("s2");
s2.ChartType = ChartType.Column;
Series s3 = c.Series.Add("s3");
s3.ChartType = ChartType.Line;
Forgive the poor ASCII art, but the legend looks like:
.......[yellow] s2 .......[red] s3 ......[blue] s1 ............
when I would like it to go in order: s1, s2, s3.
Any ideas?

That seems very strange indeed. To me it seems that the order of the series in the legend should be the same as the order in which you add them, or if you set the LegendItemOrder property of your Legend instance to ReversedSeriesOrder in the reversed order.

To expand on Emil's answer, the MSDN info for LegendItemOrder says:
If the LegendItemOrder property is set to Auto, the legend will automatically be reversed if StackedColumn, StackedColumn100, StackedArea or StackedArea100 chart types are used.
I'm not certain, but my guess is that it's "grouping" s2 and s3, and displaying them in reverse because s1 is a StackedColumn chart - s1, (s2, s3) becomes (s2, s3), s1. (I have no idea what actually happens behind the scenes)
As Emil said, setting the LegendItemOrder property to LegendItemOrder.SameAsSeriesOrder or LegendItemOrder.ReversedSeriesOrder should force the legend to display in a certain order.
And here's a link to MSDN that has a bit more information:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.legend.legenditemorder.aspx

MSChart1.ShowLegend = True
With MSChart1
.Column = 1
.Row = 1
.ColumnLabel = "Series 1"
.Data = 100
.Column = 2
.Row = 1
.ColumnLabel = "Series 2"
.Data = 100
End With

Related

Cell formating based on other cell value google sheets

I have 2 sheets the first one is Orders and second one is the ShippingDoc.
At Shipping doc, I have Cell C2. In that cell I choose/write ID from range of A7:A from Orders.
Is there a way if I choose example ID 1 at C2 then automatically A7 at Orders to change background to green. Also if I change the ID to 2 the A8 to be green and to not delete the A7 color.
There is a better way of achieving this using Apps Script. Go to tools->Script editor and there use the following code (explained on the comments in the code):
// Update everytime the value on C2 changes
function onEdit() {
var spreadsheet = SpreadsheetApp.getActive();
// Get C2 value
var C2value = spreadsheet.getSheetByName("ShippingDoc").getRange('C2').getValue();
// If input value is higher than 0
if(C2value>0){
// Ofset to set the background after A7
var number = C2value+6;
// Set background color of appropiate cell
spreadsheet.getSheetByName("Orders").getRange('A'+number+'').setBackground('green');
}
}
Check out more information about how to do amazing things in sheets with simple scripts HERE
I hope this has helped you. Let me know if you need anything or if you did not understand something.
try:
=(REGEXMATCH(""&INDIRECT("ShippingDoc!C2"), ""&A1))*(A1<>"")

Python-docx - How to change table font size?

table = document.add_table(rows=1, cols=1)
hdr_cells = table.rows[0].cells
hdr_cells[0].text = 'Qty'
I have to change font size of text 'Qty' in table with one row and one column, how can I make it?
You need to get the paragraph in the cell. From the documentation of python-docx:
3.5.2 _Cell objects:
class docx.table._Cell (tc, parent)
paragraphs
List of paragraphs in the cell. A table cell is required to
contain at least one block-level element and end with a paragraph. By
default, a new cell contains a single paragraph. Read-only
Reference: python-docx Documentation - Read the Docs
The code:
To change font size of text 'Qty'
paragraph =hdr_cells[0].paragraphs[0]
run = paragraph.runs
font = run[0].font
font.size= Pt(30) # font size = 30
To change font size of the whole table:
for row in table.rows:
for cell in row.cells:
paragraphs = cell.paragraphs
for paragraph in paragraphs:
for run in paragraph.runs:
font = run.font
font.size= Pt(30)
Reference of how to access paragraphs in a table: Extracting data from tables
Up there the solution really helped. I use it for a while. But I found a tiny problem:time. As your table grows bigger the time you cost to build the table getting longer. So I improve it. Cut two rounds. Here you are:
The code changes the whole table
for row in table.rows:
for cell in row.cells:
paragraphs = cell.paragraphs
paragraph = paragraphs[0]
run_obj = paragraph.runs
run = run_obj[0]
font = run.font
font.size = Pt(30)
When you cut two rounds you save the time
Building on user7609283 answer, here is a short version to set a cell to bold (the cell must contain text before applying format as it looks for the first paragraph):
row_cells = table.add_row().cells
row_cells[0].text = "Customer"
row_cells[0].paragraphs[0].runs[0].font.bold = True
This font change applies to all cells of a table and is streamlined. All cells must contain text before being formatted or an index out of range error is thrown:
for row in table.rows:
for cell in row.cells:
cp = cell.paragraphs[0].runs
cp[0].font.size = Pt(14)
This next font change applies to a single cell as wanted, in this case the top left cell:
tc = table.cell(0, 0).paragraphs[0].runs
tc[0].font.size = Pt(14)

Format a text on cell in two color in Coldfusion

Using Coldfusion 10, I need to format a cell contents in two color(Black and Blue). Let a cell on spreadsheet contains a string "Text1: Text2". where color of "Text1" should be black and "Text2" should be blue.
I have tried below code, but it produces all blue text.
SpreadsheetAddRow(spreadsheetData,"Text1: Text2",1,1);
format1=StructNew();
format1.color="black";
SpreadsheetFormatRow(spreadsheetData,format1,1);
format1.color="blue";
SpreadsheetFormatRow(spreadsheetData,format1,1);
How I can apply two color to format single cell ?
It is not supported with the built in functions. However, you can tap into the underlying POI library and use a RichTextString to accomplish this.
Assuming you have already created the worksheet and an empty cell:
spreadsheetData = SpreadSheetNew("Sheet1", true);
SpreadsheetAddRow(spreadsheetData,"",1,1);
Grab reference to the underlying Workbook and create fonts with the appropriate colors:
wb = spreadsheetData.getWorkbook();
Colors = createObject("java", "org.apache.poi.ss.usermodel.IndexedColors");
greenFont = wb.createFont();
greenFont.setColor(Colors.GREEN.index);
blueFont = wb.createFont();
blueFont.setColor(Colors.BLUE.index);
Then create a RichTextString object and append each part of the text with the desired color:
// Using GREEN and BLUE for demo purposes
richString = createObject("java", "org.apache.poi.xssf.usermodel.XSSFRichTextString").init();
richString.append("Text1: ", greenFont);
richString.append("Text2", blueFont);
Finally, apply the RichTextString to the empty cell, ie A1 you created earlier. Note, unlike in CF, the indexes are 0-based.
cell = wb.getSheet("Sheet1").getRow( 0 ).getCell( 0 );
cell.setCellValue(richString);

Position title Aspose slide chart

Is it possible to position the title of a Aspose powerpoint slide chart?
I have tried following:
chart.ChartTitle.X = 100;
chart.ChartTitle.Y = 100;
With different values but title is not moved.
Since it is not possible to move the chart title I simply created a title just above the chart using a regular autoshape, something like this:
IAutoShape autoshape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 20, 0, 600, 50);
autoshape.UseBackgroundFill = true;
autoshape.LineFormat.FillFormat.FillType = FillType.NoFill;
autoshape.AddTextFrame(" ");
ITextFrame txtFrame = autoshape.TextFrame;
IParagraph para = txtFrame.Paragraphs[0];
IPortion portion = para.Portions[0];
portion.Text = title;
portion.PortionFormat.FillFormat.SolidFillColor.Color = Color.Black;
portion.PortionFormat.FillFormat.FillType = FillType.Solid;
I have observed the code shared by you and it is Ok despite the values set for it. Inside the chart area the value is between 0-1. (0,0)(X,Y) being the bottom left and (1,1)(X,Y) being top right corner of chart. But still this feature is not working and there seems to be issue in API. You can contact Aspose.Slides support team over following link to log request for your issue.
http://www.aspose.com/community/forums/aspose.slides-product-family/109/showforum.aspx
Yes, you are right. This is an alternate approach that you may try on your end to super impose an auto shape containing the chart title as overlay on the chart. However, in this approach you need to identify the appropriate position of auto shape over the chart to serve as title.
Yes this is one of the alternates that you can use on your end.

Different color for table of contents entry and page numbers

I am generating a clickable (=with links) table of contents. In order to emphasize the 'clickability' of the entries I want them colored as links (i.e. blue color and underline).
I have this code for setting the style:
toc = TableOfContents()
toc.levelStyles[0].fontName = 'Arial Bold'
toc.levelStyles[0].fontSize = 12
toc.levelStyles[0].textColor = '#0000cc'
and use this code to add each entry:
toc.addEntry(0, '<u>' + entrytext + '</u>', pageNum, str(id(page)))
It works ok, the problem is that page numbers turn out blue as well. I tried to look around SO and the user guide for ways to put a different style for each - but was unsuccessful. Any ideas?
Thanks.