I am using Microsoft.Office.Interop.Excel to create a chart. Some of my series in chart series collection are logarithmic, so I want to get hold of axis related a particular series, to set scale type to logarithmic.
Here is a way you could do it:
xlAxisValue = CType(xlChart.Axes(, Excel.XlAxisGroup.xlPrimary), Excel.Axes)
xlAxisValue.Item(Excel.XlAxisType.xlValue).ScaleType = Excel.XlScaleType.xlScaleLogarithmic
It is a generic example, if it is not working plese post your code.
Related
I need to add a trendline to an Excel scatterplot. There's a class in the EPPlus library - ExcelChartTrendline.cs - that is clearly intended to support this. There is also an Enum - eTrendLine that allows me to specify the type of line.
The code for adding the scatterplot was simple and the chart renders fine:
var chart = worksheet.Drawings.AddChart(chartName, eChartType.XYScatter);
But after a many hours searching and tinkering I cannot figure out the syntax for adding the trendline.
You have to get reference to the serie that is created when adding the chart series to access the TrendLines collection. Like this:
var chart = worksheet.Drawings.AddChart("chart test", eChartType.XYScatter);
var series = chart.Series.Add(worksheet.Cells["B1:B10"], worksheet.Cells["A1:A10"]);
series.TrendLines.Add(eTrendLine.Linear);
I am trying to add data labels to all my series in a bar chart but the amount of series varies from chart to chart because this is a function used for many charts. So, I used a For Loop to add them, but I need to determine the size of the SeriesCollection array. Would there be a function that would do so? When I try to use .Size it gives me an error.
Below is what I tried:
With Chart
For i = 1 To .SeriesCollection.Size
.SeriesCollection(i).Points(i).HasDataLabel = True
Next i
End With
Some of the stuff in the Chart object model isn't properly hooked up to Intellisense. You'll notice that you get no suggestions when you type .SeriesCollection.
.SeriesCollection.Count will give you what you're after, I think.
I have an application made of a "main" chart with stock quotes plotted in it and a "subordinated" one with some indicators; the two charts are dinamically feeded with data so they are ever moving and re-sizing their own YAxis accordingly. The following snapshot gives a better idea:
What I would like to do is to make the below chart XAxis exactly the same of the first one, so that it is possible to follow the evolution of the two indicators together.
Right now I'm doing the following work around:
With ChartBelow.ChartAreas(0)
.AxisX.Minimum = ChartAbove.ChartAreas(0).AxisX.Minimum
.AxisX.Maximum = ChartAbove.ChartAreas(0).AxisX.Maximum
End With
However this doesn't work well since the digits of the YAxis on the main chart are not always the same of the second one (as in the example above where it's 6-digits against 3-only).
Is there any way to aligne the two y-axes or make the X-Axis shared between the two charts?
Yes, as well as setting the Min/Max values, also set the interval and label interval values of the Axis.
ChartAbove.ChartAreas(0).XAxis.Interval
ChartAbove.ChartAreas(0).XAxis.LabelStyle.Interval
I'm building a simple forecasting tool in Excel which contains several dynamically created groups of charts via VBA.
Each group contains two charts. The first chart plots a static set of data stored in an array as well as user input in a range. I would like the second to plot the difference between the user input (range) data and the static data (array).
I'm not having any problems setting the data for the first chart:
objCht.Chart.SeriesCollection(1).values = testForecast.Forecast(i)
objCht.Chart.SeriesCollection(2).Values = groupActualRange
but I'm not having any luck when it comes to the second.
Is there any way to set the values for the second chart without having to create a second array to store to differences between the values and set application.volatile to true to capture new input?
I have an array of type Double() (1 x n) that I am trying to quickly plot on a graph I've already set up. The only thing I want/need to do is take my array and store it as data points (y-axis values) in the series I already have. What's the best way to do this? Also, will the data points that are plotted change as my array changes, and if not, how would I replot those new points and get rid of the old points?
Adding the points should be as simple as
Chart1.Series("Default").Points.Add(arrayName)
As for it being auto-updated when you change the array, I believe if you just add the points, you are going to have an issue like pee in a swimming pool (once they are in there, you can't get them out). So, you add an array with 3 items, then add a double to the array, then the add to the chart again, you now incorrectly have 7 points. However, you can databind the array to the series, like so.
Chart1.Series("Default").Points.DataBindXY(xStrings, xDoubles)
In this case, if the array changes, the chart should change as well.