https://github.com/reddec/svg
Lightweight C plotting library without special dependencies for Linux and Win
https://github.com/reddec/svg
Last synced: 9 months ago
JSON representation
Lightweight C plotting library without special dependencies for Linux and Win
- Host: GitHub
- URL: https://github.com/reddec/svg
- Owner: reddec
- License: mit
- Created: 2014-06-05T11:34:39.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2021-02-19T04:53:45.000Z (over 5 years ago)
- Last Synced: 2025-10-12T05:05:45.011Z (9 months ago)
- Language: C
- Size: 96.7 KB
- Stars: 12
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
svg
===
Lightweight C plotting library without special dependencies for Linux and Win.
Developed with C89 standart. Successfull build on gcc-4.8 and Visual C compiller 2010
## Example
```c
#include
#include
#include
#include "svg.h"
int main(int argc, char** argv)
{
int size = 410, i;
double *data = (double*) malloc(sizeof (double)*size);/*Allocate test y array*/
double *x = (double*) malloc(sizeof (double)*size); /*Allocate test x array*/
FILE *f;
for (i = 0; i < size; ++i) /*Fill x and y values*/
{
data[i] = 50 + 50 * sin(i * 0.03);
x[i] = i;
}
f = fopen("sin.svg", "w"); /*Open result file*/
/* Plot graphic with red (#ff0000) lines as svg image only */
svg_draw_to_file_xy(f, "#ff0000", data, x, size, "x", "sin(x)", 2, false);
fclose(f); /*Close result file*/
free(data); /* Free y array */
free(x); /* Free x array */
return (EXIT_SUCCESS);
}
```
Compile the example:
```
$ gcc main.c svg.c -lm
$ ./a.out
```
Output of `sin.svg`:

## API
Full version
```c++
void svg_draw_to_file_xy(
FILE *f,
const char *color,
double *y,
double *x,
size_t count,
const char *xlabel,
const char *ylabel,
int decimal,
bool html)
```
Short version with auto generated X (from 0 to count-1)
```c++
void svg_draw_to_file_y(
FILE *f,
const char *color,
double *y,
size_t count,
const char *xlabel,
const char *ylabel,
int decimal,
bool html)
```
* **f** - reference to opened file for writing result
* **color** - line color
* **y** - array with values
* **x** - sorted array with x values from minimum to maximum
* **count** - elements count (not bytes)
* **decimal** - number after dot in float
* **html** - generate or not html page with inline svg. Usefull for Windows users, which do not have other good SVG viewer then browsers