LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-24-2011, 05:07 AM   #1
dlucey
LQ Newbie
 
Registered: Feb 2011
Posts: 4

Rep: Reputation: 0
how to generate excel charts from c


Hi,

Does anybody know how to generate excel charts from C, or if it's possible at all?

For example, if I had 2 arrays that I wanted to export to excel and graph against each other. I know how to export it to a csv file, that's no problem, but I have no idea where to start with generating a graph of the data. I can't seem to find any examples anywhere.

I'd appreciate if someone could point me in the right direction.

Just a simple example to show you what I mean:
Code:
char arr1[] = {'a','b','c'};
int arr2[] = {10,20,30};

int main () 
{

FILE *myfile= fopen ("example1.csv","w");

for (int i=0; i<3; i++)
    fprintf(myfile, "%c,%d\n",arr1[i],arr2[i]);    

fclose(myfile);
return 0;
}
Thanks
 
Old 02-24-2011, 08:45 AM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Start by telling us whether or not this is homework, as that affects the types of solutions that are available to you.
 
Old 02-24-2011, 08:57 AM   #3
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by dlucey View Post
Does anybody know how to generate excel charts from C, or if it's possible at all?
If you really really need to do that, there is source code available in the OpenOffice project that can export to Excel file formats. But finding, extracting and using that source code would be very hard.

Quote:
I know how to export it to a csv file, that's no problem,
I assume you also know how to import csv when running Excel. That is quite easy.

Quote:
but I have no idea where to start with generating a graph of the data.
Do you mean that while running Excel (after importing a csv file) you don't know how to get Excel to display a graph of the data you imported?

The Excel help tool isn't great, but it is effective for basic tasks like that with easily search-able keywords. Try using Excel help.

Or is it, for some reason, important that the file you write from your C program includes the graphing instructions as well as the data (so no manual steps would be required after importing into Excel)? That would be far harder to achieve. Hard enough that if that was your goal, you probably want to rethink the goal.

Quote:
I have no idea where to start with generating a graph of the data.
Maybe the part of your goal you should rethink is the Excel part. If you want a C program to graph data, there are plenty of good open source tools to do so. Just ask the right question and I'm sure someone would post some good links.

Directly graphing without Excel would be harder to code than exporting CSV then manually setting up a graph in Excel; But it would be much easier than exporting from a C program a true Excel file including the setup of the graph.

Last edited by johnsfine; 02-24-2011 at 09:01 AM.
 
Old 02-24-2011, 09:40 PM   #4
dlucey
LQ Newbie
 
Registered: Feb 2011
Posts: 4

Original Poster
Rep: Reputation: 0
My apologies... I wrote down excel without thinking, i meant to say openoffice or similar spreadsheet on linux.

I have been able to export the data to an openoffice spreadsheet. I just need to be able to code my c program to generate a graph of this data automatically too if this is possible.

This is a college project I'm working on.

Again, my apologies for wasting your time.

Thanks
 
Old 02-24-2011, 10:02 PM   #5
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Create a GTK or Qt window with a drawing surface (for example, a QPainter) and then just use the primitive drawing commands to draw the graphs.

Another method would be to get a HTTP library and then call the Google Chart API.

Last edited by dugan; 02-24-2011 at 10:58 PM.
 
Old 02-24-2011, 11:03 PM   #6
someshpr
Member
 
Registered: Jul 2009
Location: WI, USA
Distribution: Debian 8, Ubuntu 16.04, CentOS 7
Posts: 143

Rep: Reputation: 28
If automatically generating graph from some data is your main goal, may be you can try gnuplot. Generating plots automatically in excel/openoffice format doesn't seem to be straight forward.

I have not thought it through properly but may be something can be done along this line (all in your c code):
1. Create the data file;
2. Create an appropriate plotting script for gnuplot;
3. Call "gnuplot plotting.script" from your c code using system call.
 
Old 02-24-2011, 11:22 PM   #7
dlucey
LQ Newbie
 
Registered: Feb 2011
Posts: 4

Original Poster
Rep: Reputation: 0
Yes, automatically generating a graph from the data is the main objective here.

Thanks for the suggestions, unfortunately time isn't on my side, so I may have to leave it out if I can't get it working, but I'll see how I get on.

From what I can tell gnuplot seems to be the simplest way of doing it, so I'll try to use that.

Thanks.
 
Old 02-25-2011, 08:18 AM   #8
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
It's pretty easy to draw graphs using Qt's QPainter. But Qt doesn't work in C. You would have to use something like C++ or Python (which is probably the easiest way).
 
Old 02-25-2011, 09:05 AM   #9
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
I've used gnuplot before.
It's probably what you need.
It seems a bit odd at first, like vi, but spend a day getting to know it
and you'll find it powerful, like vi. There's a little cheat sheet in the docs
which is very handy.
also ploticus http://ploticus.sourceforge.net/doc/welcome.html
is quite popular though I aint tried it.

If you compare gnuplot and ploticus, please let us know, as I will be
doing similar quite soon, I'd be interested in hearing.

edit: just had a look gnuplot is much more powerful.

Last edited by bigearsbilly; 02-25-2011 at 09:33 AM.
 
Old 02-25-2011, 01:54 PM   #10
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Yes, in Linux land, gnuplot seems to be the de facto standard for embedded plotting. I have used it in Perl scripts and shell scripts, and from it's nature, it looks like it should be possible to embed it in most compiled languages that provide filesystem &/or exec semantics. It is used as the plotting package in the Matlab work-alike, Octave. It is a very versatile and fast plotting package. It biggest drawback is the bewildering array of commands and options that can be used.

--- rod.
 
Old 02-26-2011, 04:50 AM   #11
dlucey
LQ Newbie
 
Registered: Feb 2011
Posts: 4

Original Poster
Rep: Reputation: 0
Yes gnuplot seems to be the best option for me.

Quote:
It's pretty easy to draw graphs using Qt's QPainter. But Qt doesn't work in C. You would have to use something like C++ or Python (which is probably the easiest way).
I don't really have the option to change to c++ or python as this will be part of a much larger program which is already written. This is just the final step.

I'll give gnuplot a go and hopefully be able to get that working. Hopefully I won't have to come back here looking for help with the code!

Thanks for all the help though, much appreciated.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Networking Reference Charts. farslayer Linux - Networking 3 11-26-2008 04:10 PM
Charts in C++ manolakis Programming 6 09-26-2007 10:59 AM
Excell Macros, Charts etc. io86 Linux - Software 1 09-11-2006 02:23 AM
Gant Charts? mikedeatworld Linux - Software 2 10-18-2004 07:41 AM
software for graphs and charts alainhenry Linux - Software 2 07-06-2004 06:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration