Hi all,
I am trying to plot a graph in excel file using C#.Net.
I am using the name space excel .
If my graph has one series(2 columns), i am able to draw the graph.
if my graph has two series(4 columns), i am unable to draw the correct graph.
In this case i need graph with 2 series, one with first and second column
and the second one with third and fourth columns. But i am getting 3 curves,
one is for first and second column
second is for first and third column
third is for first and fourth column, which i dont want.
please clarify my problem if you hav answers.
Thanks in advance
Bye
5 20014
Welcome to the site. Please post your relevant code. Do receive any errors?
xla = new Excel.Application();
xla.Visible = true;
Workbook wb = xla.Workbooks.Add(XlSheetType.xlWorksheet);
Worksheet ws = (Worksheet)xla.ActiveSheet;
ChartObjects chartObjs = (ChartObjects)ws.ChartObjects(Type.Missing);
ChartObject chartObj = chartObjs.Add(100, 20, 300, 300);
Chart xlChart = chartObj.Chart;
int[,] v1 ={ { 1, 2 ,5, 10}, { 2, 4,10, 20 }, { 3, 6 ,15,30} };
Range rg;
rg = ws.get_Range("A2", "D4");
rg.Value2 = v1;
xlChart.ChartType = XlChartType.xlXYScatterSmoothNoMarkers;
xlChart.SetSourceData(rg, Type.Missing);
in place of int[,] v1 ={ { 1, 2 ,5, 10}, { 2, 4,10, 20 }, { 3, 6 ,15,30} };(of my previous post), if i give int[,] v1 ={ { 1, 2 }, { 2, 4 }, { 3, 6} };, i am able to get
the curve. If i give int[,] v1 ={ { 1, 2 ,5, 10}, { 2, 4,10, 20 }, { 3, 6 ,15,30} };
i am getting 3 curves for the points
first curve (1,2),(2,4),(3,6)
second curve (1,5),(2,10),(3,15)
Third curve (1,10),(2,20),(3,30)
which i dont require.
What i require is
two curves
first one (1,2),(2,4),(3,6)
second curve (5,10),(10,20),(15,30)
xla = new Excel.Application();
xla.Visible = true;
Workbook wb = xla.Workbooks.Add(XlSheetType.xlWorksheet);
Worksheet ws = (Worksheet)xla.ActiveSheet;
ChartObjects chartObjs = (ChartObjects)ws.ChartObjects(Type.Missing);
ChartObject chartObj = chartObjs.Add(100, 20, 300, 300);
Chart xlChart = chartObj.Chart;
int[,] v1 ={ { 1, 2 ,5, 10}, { 2, 4,10, 20 }, { 3, 6 ,15,30} };
Range rg;
rg = ws.get_Range("A2", "D4");
rg.Value2 = v1;
xlChart.ChartType = XlChartType.xlXYScatterSmoothNoMarkers;
xlChart.SetSourceData(rg, Type.Missing);
Hi,
I am doing same but i am not able to understand how to draw a chart in side the excel. I am looking your code. What's taht xlChart ? and what is this ChartObject? do i need any assambly for that?
Thanks,
Naish
Ok so this is what you should do:
1.create a seriescollection cause you have several series (plots/lines) in one excel chart
2.create the seperate series
3. assign the values for each series. -
Excel.SeriesCollection seriesCollection;
-
Excel.Series series1, series2;
-
-
//this create the seriescollection and series
-
seriesCollection = xlChart.SeriesCollection(misValue)
-
series1 = seriesCollection.NewSeries();
-
series2 = seriesCollection.NewSeries();
-
-
//this gives each series the values. values are y values, xvalues are x values
-
series1.Values = ws.get_Range("A1", "A4") //assuming y values are in column //A, change range according to which column your values are
-
series2.XValues = ws.get_Range("B1", "B4") //if x values are in column B
-
-
//repeat for series2
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: george_y |
last post by:
I need some help to generate with a C++ programm a file in Excel format
(or at least in a way that all the information in it can be read by
Excel) containing a graph with the data I choose. As an...
|
by: KevinGPO |
last post by:
I am making a monitor program for the PC. My monitor program will grab
statistics about CPU and memory every 1 or 5 seconds. Then I want to
store this data so I have a history and hence be able to...
|
by: Russ |
last post by:
I'm interested in setting up a web page where live data can be
displayed in real-time on the web page.
For example: I would like to display a (nice looking) graph of some
data value versus time...
|
by: Chapman |
last post by:
Is it possible to plot the graph as an output of my program in C? It can be
a simple graph as quadratic curves for example
or a correlation between 2 variables only.
Thanks
|
by: wayne |
last post by:
i want to plot a line graph. The values that I obtain are the RGB value
of a TIFF image. i m plotting RGB values vs value(1,2,3..) so when
generated the RGB values, there will b a column of values...
|
by: diffuser78 |
last post by:
My python program spits lot of data. I take that data and plot graphs
using OfficeOrg spredsheet. I want to automate this task as this takes
so much of time. I have some questions.
1. Which is...
|
by: Gouri |
last post by:
Hi,
Got a query regarding plotting a preview / thumbnail for a graph
which reads data from a binary file. The preview should should take
very less time, look exactly like the original graph i.e....
|
by: 9966 |
last post by:
Greetings, I'm currently having problem in plotting a simple graph in C++. I learned that we can actually use koolplot to do it. My question is whether it is possible to plot, let's say the...
|
by: Durand |
last post by:
Hi,
I'm trying to plot a simple graph against date or time using matplotlib. I've read about date_plot but I'm not really sure how to use it. At the moment, I have some data arranged into lists,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |