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
f8014416
Commit
f8014416
authored
9 years ago
by
Tim Molter
Browse files
Options
Downloads
Patches
Plain Diff
allow for repeated categories in bar charts
parent
fb7d6f5c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickBarChartCalculator.java
+23
-16
23 additions, 16 deletions
...xchart/internal/chartpart/AxisTickBarChartCalculator.java
with
23 additions
and
16 deletions
xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickBarChartCalculator.java
+
23
−
16
View file @
f8014416
...
...
@@ -16,7 +16,6 @@
package
com.xeiam.xchart.internal.chartpart
;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Iterator
;
import
java.util.List
;
...
...
@@ -56,13 +55,13 @@ public class AxisTickBarChartCalculator extends AxisTickCalculator {
// where the tick should begin in the working space in pixels
double
margin
=
Utils
.
getTickStartOffset
(
workingSpace
,
tickSpace
);
// get all categories
List
<
Object
>
categories
=
new
ArrayList
<
Object
>();
List
<?>
firstXAxis
=
(
List
<?>)
chartPainter
.
getAxisPair
().
getSeriesMap
().
values
().
iterator
().
next
().
getXData
();
Series
firstSeries
=
chartPainter
.
getAxisPair
().
getSeriesMap
().
values
().
iterator
().
next
();
// we use this to check
all series have
the
exact
same length and value
s
for
(
Series
series
:
chartPainter
.
getAxisPair
().
getSeriesMap
().
values
()
)
{
// verify
all series have exact
ly the same xAxi
s
if
(
chartPainter
.
getAxisPair
().
getSeriesMap
().
size
()
>
1
)
{
Iterator
<?>
firstSeriesItr
=
firstSeries
.
getXData
().
iterator
();
for
(
Series
series
:
chartPainter
.
getAxisPair
().
getSeriesMap
().
values
())
{
Iterator
<?>
firstSeriesItr
=
firstXAxis
.
iterator
();
Iterator
<?>
xItr
=
series
.
getXData
().
iterator
();
while
(
xItr
.
hasNext
())
{
...
...
@@ -72,6 +71,17 @@ public class AxisTickBarChartCalculator extends AxisTickCalculator {
if
(!
firstSeriesNext
.
equals
(
next
))
{
throw
new
IllegalArgumentException
(
"X-Axis data must exactly match all other Series X-Axis data for Bar Charts!!"
);
}
}
}
}
for
(
Series
series
:
chartPainter
.
getAxisPair
().
getSeriesMap
().
values
())
{
Iterator
<?>
xItr
=
series
.
getXData
().
iterator
();
while
(
xItr
.
hasNext
())
{
// check matching
Object
next
=
xItr
.
next
();
Object
x
=
null
;
if
(
chartPainter
.
getAxisPair
().
getXAxis
().
getAxisType
()
==
AxisType
.
Number
)
{
...
...
@@ -83,25 +93,22 @@ public class AxisTickBarChartCalculator extends AxisTickCalculator {
else
if
(
chartPainter
.
getAxisPair
().
getXAxis
().
getAxisType
()
==
AxisType
.
String
)
{
x
=
next
;
}
if
(!
categories
.
contains
(
x
))
{
categories
.
add
(
x
);
}
}
}
if
(
chartPainter
.
getAxisPair
().
getXAxis
().
getAxisType
()
==
AxisType
.
String
)
{
double
gridStep
=
(
tickSpace
/
(
double
)
categorie
s
.
size
());
double
gridStep
=
(
tickSpace
/
(
double
)
firstXAxi
s
.
size
());
double
firstPosition
=
gridStep
/
2.0
;
int
counter
=
0
;
for
(
Object
category
:
categorie
s
)
{
for
(
Object
category
:
firstXAxi
s
)
{
tickLabels
.
add
(
category
.
toString
());
double
tickLabelPosition
=
margin
+
firstPosition
+
gridStep
*
counter
++;
tickLocations
.
add
(
tickLabelPosition
);
}
}
double
gridStep
=
(
tickSpace
/
(
double
)
categorie
s
.
size
());
double
gridStep
=
(
tickSpace
/
(
double
)
firstXAxi
s
.
size
());
double
firstPosition
=
gridStep
/
2.0
;
// generate all tickLabels and tickLocations from the first to last position
...
...
@@ -116,7 +123,7 @@ public class AxisTickBarChartCalculator extends AxisTickCalculator {
}
int
counter
=
0
;
for
(
Object
category
:
categorie
s
)
{
for
(
Object
category
:
firstXAxi
s
)
{
if
(
chartPainter
.
getAxisPair
().
getXAxis
().
getAxisType
()
==
AxisType
.
Number
)
{
tickLabels
.
add
(
numberFormatter
.
formatNumber
(
new
BigDecimal
(
category
.
toString
()),
minValue
,
maxValue
,
axisDirection
));
}
...
...
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