Excel C# API Chart class Interior property missing - c#

I am trying to create a chart with Excel API in C#. It is going really well, but I don't have some fields.
For example:
Format Excel Chart Background using C#
At this question, James' answer is something I'm looking for but:
The object does not have an Interior property.
And again:
Chart Properties
I see something like ChartColor:
But my charts don't have it.
I though it depends on the type of the chart, but it is just defined inside and doesn't affect the fields (tried to do something like casting, but it was just 'not-smart' heroic try).
I also tried to do an example of chart and just ascribe all attributes, but still there is nothing like Color.
I don't want a background image, just a background hue!
I have the latest Microsoft.Office.Interop.Excel library, but tried on older ones and effect is the same.
Where is the problem?
P.S.
I'm also working with copying all attributes of chart except data, name and axis names. If someone of You did something like that, I would be grateful for any information.
EDIT:
Fixed it just by load example chart and use SetSourceData. But why I can't do it programmatically?

"Where is ChartColor?": It's probably just an Intellisense bug. Usually happens when I sleep the computer too many times without closing VS. Try closing and reopening VS. Also, have you tried just running the code with chart.ChartColor?
"There's nothing like interior": Interior refers to an sub-area that can be formatted. The chart object itself isn't what you want to color. It's the ChartArea that contains Interior, which has a ColorIndex, so try
Excel.Interior interior = chart.ChartArea.Interior;
I'm sorry that wasn't clear in Format Excel Chart Background using C#. You'll need to be wary of posters that answer their own questions. Sometimes, it's ok, but more often, it's "I fixed it with this line" which doesn't help anyone else when taken out of context.
"Where's my problem?": It depends on your implementation. Including some example code helps tremendously on StackOverflow. Some are looking to create a chart as part of a worksheet, like:
Excel.Shape shape = worksheet.Shapes.AddChart2();
Excel.Chart chart = shape.Chart;
Or some developers want to create a chart as a new sheet, like this:
Excel.Chart chart = workbook.Charts.Add();
These are both charts, but behave differently because of their implementation.

Related

Is there an option in chart.js to hide values in the graph legend

I've picked up a project from a former colleague but know nothing about javascript and/or chart.js, I'm trying to learn.
I've been asked to part of the graph/legend - red ring in the image.
The thing is the chartjs json string/structure is split into separate variables which make it pretty hard to follow - and also give code samples. I've tried changing the "options" string, i.e. options: {legend: {display:false }}, but it's still displaying.
Is the part marked red actually part of the legend or is it something else on the chart
Image showing what I need to hide
That isn't the legend. Somewhere in the options there is a property xAxes. Here your collegue has defined multiple new axes. These are the ones you see. If you remove them and remove the xAxisId from the datasets you will get what you want

Infragistics XamDataChart: How to use NumericXAxis for CategorySeries like ColumnSeries, AreaSeries and so on?

Title of my question probably is descriptive enough, yet here is the rest:
I need to plot histograms and area charts for some numeric values. I already managed to do it partially using a CategoryXAxis, the only option which ColumnSeries Supports.
Unfortunately labels don't show good enough (Position, Spacing, ...) and also Tick Markers are meant to be for category data and show between Columns.
As the task looks really trivial, and i need to do this many times with different options, i was thinking maybe there is a way to do this using a NumericXAxis which is pretty simple and meant to be used for numeric data.
Unfortunately i don't see a way to convert use NumericXAxis for ColumnSeries? So I hope someone could help me on this.
Requirements: I use .Net Framework 4.0, C#, WPF
Note: I'm more interested in Code-Behind rather than XAML.

embed a button into an excel chart

Roughly speaking, I want to create a child class from Excel Chart to add the following features into the child:
add a button to the visual appearance of the chart (the button should have a fixed position relatively to the chart - so if I move chart, the button moves as well). Actually, it doesn't have to be exactly button - it may be anything else which allows clicking on it (or do any other action) and do some activities after the click.
add some additional properties to the chart (these properties doesn't appear vizually but they influence the representation of the time-series). Maybe there is a standard way to customize the set of the properties of Excel Chart?
I don't know to what extent it is possible. Maybe "child class" is not that good idea to serve such simple needs. Maybe VSTO has something, but I can't find anything suitable in the Internet.
Any help will be very much appreciated!
PS
For the subquestion #2 I've decided to use the field TAG to put there an object with additional parameters.
In answer to your first question it is possible to embed a form-control button or a shape in a chart, and have it keep its position relative to the chart area, by cutting and pasting it onto the chart. Use the OnAction property to assign a procedure to the button.
Recorded code (in Excel) is like this:
Sub Macro1()
ActiveSheet.Buttons.Add(166.5, 48, 48, 32.25).Select
Selection.OnAction = ActiveWorkbook.Name & "!TestMacro"
Selection.Cut
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Paste
Selection.ShapeRange.IncrementLeft 10
Selection.ShapeRange.IncrementTop 30
End Sub
It may be possibly to do this programmatically without cutting and pasting, perhaps by adding to the ChartObject's ShapeRange, but I haven't explored this.
I do not know to what extent you can directly subclass an Excel Chart (if at all) and suspect that you might just create a wrapper class for it in C#.

Get height of rendered text and images in MS Word

I'm creating a newspaper authoring system. Today I'm using Aspose.Words library to generate newspaper using Docx format as output, based on a lot of other documents as input.
The basic idea is to load a lot of articles documents into a List, then generate a final docx with newspaper.
We need to get the total height of a text (with images and tables) inside columns. As libraries like Aspose.Words deal with Docx format like DOM, there isn't way to know how text will be arranged inside columns. Then I can't know the real height.
We've worked in our own way to get this height. I'm using MeasureString() function from System.Drawing.Graphics namespace. It returns width and height used by string and I can estimate how many lines (and points or inches) it will use inside a column.
But it is very poor and we need a more decent solution. We are thinking to use OpenXML SDK to get this Height, can we?
Aspose.Words doesn't support a way to know it and all Render classes are private to the library.
Can you think a new way to get this height?
Thank you,
Daniel Koch
This property isn't exposed in Open XML or the SDK (or VBA/VSTO for that matter). How exactly the height is calculated is not in any documentation. Possibly the way you are doing it is a way to proceed.
Another possible way is to put your TextColumns in a Table Column/Cell and grab that height (but if it is two text columns in the cell and the first one "fills" the cell top to bottom and the second one doesn't, you'll still have the issue of not being able to calculate the size of the second one).
I have almost the same problem that you have.. But in my case I'm dealing with Questions inside an Test Exam..
Well nowadays, we are using RTF to build the questions and a RichTextBox the measure the height.. Just like that (http://blogs.technet.com/david_bennett/archive/2005/04/06/403402.aspx)..
And I wanna to migrate to DOCX.. But still no luck on how to measure the question with tables and images.. :-(
Right now I'm studying the Document Members (http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word._document_members.aspx), to try to do with Word Automation..
Regards,
Bruno
Thank all for answer.
I finished it changing Aspose.Words to PDFLib. Now I can control pages, columns or anything using Postscript Points.
We keep Aspose.Words only to content import, but it isn't indicate to print newsletter.

Format Excel Chart Background using C#

I can already populate the data into the spreadsheet, create the chart based on the range I select. However, when it comes to formatting the actual chart I feel a bit lost as their are so many options!!
It is an xlCylinderBarStacked type chart. I simply need to make the color of the bars a nice light orange and make the background a light blue fading into white at the bottom.
Any idea's how to do this?
Just to close this question off. I played around a little with the properties and the following achieved the gradient effect on the background of the chart.
xlChart.Interior.Color = ColorTranslator.ToOle(Color.LightSkyBlue);
chart.ChartArea.Fill.TwoColorGradient(
Microsoft.Office.Core.MsoGradientStyle.msoGradientHorizontal,
1);
One good trick with Excel and other VBA-enabled apps is to manually create the formatting/content you require using the Excel GUI, whist recording a 'macro'. Once this is done you can then inspect the generated VBA to see how to use the API to acheive the same results programmatically. You will of course have to do some translation from VBA to C# but essentially the same methods should work.

Categories

Resources