Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
segp14
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
segp14-2021
segp14
Commits
6665d0f7
Commit
6665d0f7
authored
4 years ago
by
devkanani25
Browse files
Options
Downloads
Patches
Plain Diff
Added latest revision of ChartDisplay.java to branch, old revision is commented out underneath
parent
e38d81a9
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ChartDisplay.java
+151
-0
151 additions, 0 deletions
src/ChartDisplay.java
with
151 additions
and
0 deletions
src/ChartDisplay.java
+
151
−
0
View file @
6665d0f7
/*
Allows the user to select a metric and a time interval for each data point
Generates and displays a chart of the selected data
Allows the user to print the chart
*/
import
javafx.application.Application
;
import
javafx.event.ActionEvent
;
import
javafx.event.EventHandler
;
import
javafx.geometry.Insets
;
import
javafx.geometry.Pos
;
import
javafx.print.PrinterJob
;
import
javafx.scene.Group
;
import
javafx.scene.Scene
;
import
javafx.scene.chart.BarChart
;
import
javafx.scene.chart.CategoryAxis
;
import
javafx.scene.chart.NumberAxis
;
import
javafx.scene.chart.XYChart
;
import
javafx.scene.control.Button
;
import
javafx.scene.control.CheckBox
;
import
javafx.scene.control.ComboBox
;
import
javafx.scene.control.Label
;
import
javafx.scene.layout.GridPane
;
import
javafx.scene.layout.HBox
;
import
javafx.scene.layout.StackPane
;
import
javafx.scene.layout.VBox
;
import
javafx.stage.Stage
;
public
class
ChartDisplay
extends
Application
{
@Override
public
void
start
(
Stage
primaryStage
)
throws
Exception
{
primaryStage
.
setTitle
(
"Chart Display"
);
ComboBox
metricsChoice
=
new
ComboBox
();
metricsChoice
.
getItems
().
add
(
"Number of Impressions"
);
metricsChoice
.
getItems
().
add
(
"Number of Clicks"
);
metricsChoice
.
getItems
().
add
(
"Number of Uniques"
);
metricsChoice
.
getItems
().
add
(
"Number of Bounces"
);
metricsChoice
.
getItems
().
add
(
"Number of Conversions"
);
metricsChoice
.
getItems
().
add
(
"Total Cost"
);
metricsChoice
.
getItems
().
add
(
"CTR"
);
metricsChoice
.
getItems
().
add
(
"CPA"
);
metricsChoice
.
getItems
().
add
(
"CPC"
);
metricsChoice
.
getItems
().
add
(
"CPM"
);
metricsChoice
.
getItems
().
add
(
"Bounce Rate"
);
metricsChoice
.
setValue
(
"Choose metric"
);
ComboBox
timeChoice
=
new
ComboBox
();
timeChoice
.
getItems
().
add
(
"1 hour"
);
timeChoice
.
getItems
().
add
(
"1 day"
);
timeChoice
.
getItems
().
add
(
"1 week"
);
timeChoice
.
setValue
(
"Choose time period"
);
Button
confirmMetric
=
new
Button
(
"Confirm choice"
);
Label
histogramLabel
=
new
Label
(
"Display histogram?"
);
CheckBox
histogramCheck
=
new
CheckBox
();
HBox
histogramBox
=
new
HBox
(
10
,
histogramLabel
,
histogramCheck
);
VBox
vBox
=
new
VBox
(
10
,
metricsChoice
,
timeChoice
,
histogramBox
,
confirmMetric
);
vBox
.
setMargin
(
metricsChoice
,
new
Insets
(
10
,
10
,
10
,
10
));
vBox
.
setMargin
(
timeChoice
,
new
Insets
(
10
,
10
,
10
,
10
));
vBox
.
setMargin
(
histogramBox
,
new
Insets
(
10
,
10
,
10
,
10
));
vBox
.
setMargin
(
confirmMetric
,
new
Insets
(
10
,
10
,
10
,
10
));
VBox
chartArea
=
new
VBox
(
10
);
confirmMetric
.
setOnAction
(
new
EventHandler
<
ActionEvent
>()
{
@Override
public
void
handle
(
ActionEvent
actionEvent
)
{
String
Time1
=
"Day 1"
;
String
Time2
=
"Day 2"
;
String
Time3
=
"Day 3"
;
String
Time4
=
"Day 4"
;
//Configuring category and NumberAxis
CategoryAxis
x_axis
=
new
CategoryAxis
();
NumberAxis
y_axis
=
new
NumberAxis
(
0
,
3000
,
100
);
x_axis
.
setLabel
(
"Time"
);
// This needs to change dynamically depending on the time interval chosen
y_axis
.
setLabel
(
"Number of Impressions"
);
// This needs to change dynamically depending on the metric chosen
//Configuring BarChart
BarChart
<
String
,
Float
>
barChart
=
new
BarChart
(
x_axis
,
y_axis
);
barChart
.
setTitle
(
"Metric Display Chart"
);
//Configuring Series for XY chart
XYChart
.
Series
<
String
,
Float
>
series
=
new
XYChart
.
Series
<>();
series
.
getData
().
add
(
new
XYChart
.
Data
(
Time1
,
1241
));
series
.
getData
().
add
(
new
XYChart
.
Data
(
Time2
,
1092
));
series
.
getData
().
add
(
new
XYChart
.
Data
(
Time3
,
2154
));
series
.
getData
().
add
(
new
XYChart
.
Data
(
Time4
,
1743
));
//Adding series to the barchart
barChart
.
getData
().
add
(
series
);
// configuring group and scene
Button
printChart
=
new
Button
(
"Print Chart"
);
printChart
.
setOnAction
((
event
)
->
{
PrinterJob
job
=
PrinterJob
.
createPrinterJob
();
if
(
job
!=
null
&&
job
.
showPrintDialog
(
barChart
.
getScene
().
getWindow
()))
{
boolean
success
=
job
.
printPage
(
barChart
);
if
(
success
)
{
job
.
endJob
();
}
}
});
chartArea
.
getChildren
().
addAll
(
barChart
,
printChart
);
chartArea
.
setAlignment
(
Pos
.
BOTTOM_CENTER
);
chartArea
.
setSpacing
(
10
);
chartArea
.
setMargin
(
barChart
,
new
Insets
(
5
,
5
,
5
,
5
));
chartArea
.
setMargin
(
printChart
,
new
Insets
(
5
,
5
,
5
,
5
));
}
});
// --------------------------------------------------------------------------
HBox
hBox
=
new
HBox
();
hBox
.
getChildren
().
add
(
vBox
);
hBox
.
getChildren
().
add
(
chartArea
);
Scene
scene
=
new
Scene
(
hBox
,
680
,
450
);
primaryStage
.
setScene
(
scene
);
primaryStage
.
setMinHeight
(
450
);
primaryStage
.
setMinWidth
(
680
);
primaryStage
.
show
();
}
public
static
void
main
(
String
[]
args
)
{
Application
.
launch
(
args
);
}
}
/*
import javafx.application.Application;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.event.EventHandler;
...
@@ -111,3 +261,4 @@ public class ChartDisplay extends Application {
...
@@ -111,3 +261,4 @@ public class ChartDisplay extends Application {
Application.launch(args);
Application.launch(args);
}
}
}
}
*/
\ No newline at end of file
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