ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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;
}
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.
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.
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.
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'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 ploticushttp://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.
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.
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!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.