473,385 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Plotting a graph in Excel file using C#.Net.

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
May 23 '07 #1
5 20011
kenobewan
4,871 Expert 4TB
Welcome to the site. Please post your relevant code. Do receive any errors?
May 23 '07 #2
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);
May 23 '07 #3
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)
May 23 '07 #4
naish
5
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
Dec 5 '07 #5
cwenee
1
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.

Expand|Select|Wrap|Line Numbers
  1. Excel.SeriesCollection seriesCollection;
  2. Excel.Series series1, series2;
  3.  
  4. //this create the seriescollection and series
  5. seriesCollection = xlChart.SeriesCollection(misValue)
  6. series1 = seriesCollection.NewSeries();
  7. series2 = seriesCollection.NewSeries();
  8.  
  9. //this gives each series the values. values are y values, xvalues are x values 
  10. series1.Values = ws.get_Range("A1", "A4") //assuming y values are in column //A, change range according to which column your values are
  11. series2.XValues = ws.get_Range("B1", "B4") //if x values are in column B
  12.  
  13. //repeat for series2 
  14.  
Sep 25 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
2
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...
12
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...
11
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
1
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...
7
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...
4
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....
3
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...
2
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,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.