Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
XChart
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Brady James Garvin
XChart
Commits
e5ca9b37
Commit
e5ca9b37
authored
12 years ago
by
Tim Molter
Browse files
Options
Downloads
Patches
Plain Diff
added CSV export
parent
1283d194
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
xchart-demo/src/main/java/com/xeiam/xchart/standalone/CSVChart.java
+3
-0
3 additions, 0 deletions
...o/src/main/java/com/xeiam/xchart/standalone/CSVChart.java
xchart/src/main/java/com/xeiam/xchart/CSVExporter.java
+121
-0
121 additions, 0 deletions
xchart/src/main/java/com/xeiam/xchart/CSVExporter.java
with
124 additions
and
0 deletions
xchart-demo/src/main/java/com/xeiam/xchart/standalone/CSVChart.java
+
3
−
0
View file @
e5ca9b37
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
*/
*/
package
com.xeiam.xchart.standalone
;
package
com.xeiam.xchart.standalone
;
import
com.xeiam.xchart.CSVExporter
;
import
com.xeiam.xchart.CSVImporter
;
import
com.xeiam.xchart.CSVImporter
;
import
com.xeiam.xchart.CSVImporter.DataOrientation
;
import
com.xeiam.xchart.CSVImporter.DataOrientation
;
import
com.xeiam.xchart.Chart
;
import
com.xeiam.xchart.Chart
;
...
@@ -36,6 +37,8 @@ public class CSVChart {
...
@@ -36,6 +37,8 @@ public class CSVChart {
// import chart from a folder containing CSV files
// import chart from a folder containing CSV files
Chart
chart
=
CSVImporter
.
getChartFromCSVDir
(
"./CSV/CSVChart/"
,
DataOrientation
.
Rows
,
600
,
400
);
Chart
chart
=
CSVImporter
.
getChartFromCSVDir
(
"./CSV/CSVChart/"
,
DataOrientation
.
Rows
,
600
,
400
);
CSVExporter
.
writeCSVRows
(
chart
.
getSeriesMap
().
get
(
0
),
"./CSV/CSVChartExport/"
);
// Show it
// Show it
new
SwingWrapper
(
chart
).
displayChart
();
new
SwingWrapper
(
chart
).
displayChart
();
...
...
This diff is collapsed.
Click to expand it.
xchart/src/main/java/com/xeiam/xchart/CSVExporter.java
0 → 100644
+
121
−
0
View file @
e5ca9b37
/**
* Copyright (c) 2013 Knowmtech <http://knowmtech.com>
*
* All rights reserved. No warranty, explicit or implicit, provided. In no event shall the author be liable for any claim or damages.
*
* IMPORTANT: THIS CODE IS PROPRIETARY!!! ABSOLUTELY NO DUPLICATION OR DISTRIBUTION IS PERMITTED WITHOUT EXPRESS WRITTEN PERMISSION FROM:
* M. ALEXANDER NUGENT CONSULTING 22B STACY RD, SANTA FE NM 87585 (505)-988-7016 i@alexnugent.name
*/
package
com.xeiam.xchart
;
import
java.io.BufferedWriter
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStreamWriter
;
import
java.io.Writer
;
import
java.util.Collection
;
import
java.util.Iterator
;
/**
* @author timmolter
*/
public
class
CSVExporter
{
public
static
void
writeCSVRows
(
Series
series
,
String
path2Dir
)
{
File
newFile
=
new
File
(
path2Dir
+
series
.
getName
()
+
".csv"
);
Writer
out
=
null
;
try
{
out
=
new
BufferedWriter
(
new
OutputStreamWriter
(
new
FileOutputStream
(
newFile
),
"UTF8"
));
String
csv
=
join
(
series
.
getxData
(),
","
)
+
System
.
getProperty
(
"line.separator"
);
out
.
write
(
csv
);
csv
=
join
(
series
.
getyData
(),
","
)
+
System
.
getProperty
(
"line.separator"
);
out
.
write
(
csv
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
out
!=
null
)
{
try
{
out
.
flush
();
out
.
close
();
}
catch
(
IOException
e
)
{
// NOP
}
}
}
}
public
static
void
writeCSVColumns
(
Series
series
,
String
path2Dir
)
{
File
newFile
=
new
File
(
path2Dir
+
series
.
getName
()
+
".csv"
);
Writer
out
=
null
;
try
{
out
=
new
BufferedWriter
(
new
OutputStreamWriter
(
new
FileOutputStream
(
newFile
),
"UTF8"
));
Collection
<?>
xData
=
series
.
getxData
();
Collection
<?>
yData
=
series
.
getyData
();
Iterator
<?>
itrx
=
xData
.
iterator
();
Iterator
<?>
itry
=
yData
.
iterator
();
while
(
itrx
.
hasNext
())
{
Number
xDataPoint
=
(
Number
)
itrx
.
next
();
Number
yDataPoint
=
(
Number
)
itry
.
next
();
String
csv
=
xDataPoint
+
","
+
yDataPoint
+
System
.
getProperty
(
"line.separator"
);
out
.
write
(
csv
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
out
!=
null
)
{
try
{
out
.
flush
();
out
.
close
();
}
catch
(
IOException
e
)
{
// NOP
}
}
}
}
private
static
String
join
(
Collection
<?
extends
Object
>
collection
,
String
separator
)
{
if
(
collection
==
null
)
{
return
null
;
}
Iterator
iterator
=
collection
.
iterator
();
// handle null, zero and one elements before building a buffer
if
(
iterator
==
null
)
{
return
null
;
}
if
(!
iterator
.
hasNext
())
{
return
""
;
}
Object
first
=
iterator
.
next
();
if
(!
iterator
.
hasNext
())
{
return
first
==
null
?
""
:
first
.
toString
();
}
// two or more elements
StringBuffer
buf
=
new
StringBuffer
(
256
);
// Java default is 16, probably too small
if
(
first
!=
null
)
{
buf
.
append
(
first
);
}
while
(
iterator
.
hasNext
())
{
if
(
separator
!=
null
)
{
buf
.
append
(
separator
);
}
Object
obj
=
iterator
.
next
();
if
(
obj
!=
null
)
{
buf
.
append
(
obj
);
}
}
return
buf
.
toString
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment