Inserting a striped line onto an Excel chart through COM Interop - c#

How can we add a striped line to an Excel chart using C#?
I am able to create the chart using c# but I didn't get any clue how to add a striped line.
Please make some suggestions.
Thanks

Try this:
- add a data series with a steady value ( of 50 in your case )
- move the new data series to the secondary Y axis
- synchronize the maximum for both Y axes
- set Chart Type for the new data series to Line
- set the Line Style for the new data series to a dash type
I know this is not C#, but it is C# as much as you question is :)
When I have things like this, what I'm usually doing is I "manually" do all I have to do in Excel recording a macro with all the stuff. Then I just analyze the macro. You will find a lot of useful information there.
Good luck!

Related

Excel C# API Chart class Interior property missing

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.

Table to Chart and Chart to Table update

Can any one help me out..
I wanted to have a Line Chart .. The Data to be loaded from sqlserver to that Line Chart..
One can drag the Line chart values and adjust them..
I am trying this using ChartDirectory tool.
Link
Once after adjustment of line chart, the Values to be updated to the same table..
Hopefully this makes sense, if not let me know.
Is there any tools available for this ??
Like This I want
you should try this free online tool - www.cloudyexcel.com/excel-to-graph/

superposing two or more series into one chart in asp.net

I am trying to fetch data from an oracle database and then plot the data accordingly to a chart. It should be relatively easy but the problem is I have to plot more than one field and superimpose them into the same chart. For example there would be four lines in single chart to specify four different fields. So far I can put two/multiple series into one chart with the following code
and the chart looks like this
But I want them to be superimposed on top of each other. I am not really familiar with asp charts so it would be great to have some valuable input on this.
Thanks. The end result should be something like this -
EDIT::: I see what went wrong with the output! So, what I really wanted to know is that those two value in two series will have the same axis or not! I wanted to plot two values with such difference that they couldnt overlap and thought they were using separate axis. So what I am looking for is already here , it was just wrong data values that gave me hard time. The actual figure now looks like -

Create an Excel Line - Column combination chart in C#

I am trying to create an Excel line-column combination chart using C#.
I know how to create a line chart or a column chart but I don't know how to create a combined chart.
Could anyone please point me a direction or provide a short sample code on how to create such chart?
Thanks in advance.

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