Created
October 15, 2011 05:35
-
-
Save dai0304/1289106 to your computer and use it in GitHub Desktop.
GChart subclassing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.charts4j; | |
import static com.googlecode.charts4j.Color.ALICEBLUE; | |
import static com.googlecode.charts4j.Color.BLACK; | |
import static com.googlecode.charts4j.Color.LAVENDER; | |
import static com.googlecode.charts4j.Color.WHITE; | |
import java.util.List; | |
public class MyChart extends BarChart { | |
public MyChart(List<? extends Plot> barChartPlots, List<String> axisLabelStrings) { | |
super(Plots.copyOf(barChartPlots)); | |
// Defining axis info and styles | |
AxisStyle axisStyle = AxisStyle.newAxisStyle(BLACK, 13, AxisTextAlignment.CENTER); | |
AxisLabels score = AxisLabelsFactory.newAxisLabels("Score", 50.0); | |
score.setAxisStyle(axisStyle); | |
AxisLabels year = AxisLabelsFactory.newAxisLabels("Year", 50.0); | |
year.setAxisStyle(axisStyle); | |
// Adding axis info to | |
addXAxisLabels(AxisLabelsFactory.newAxisLabels(axisLabelStrings)); | |
addYAxisLabels(AxisLabelsFactory.newNumericRangeAxisLabels(0, 100)); | |
addYAxisLabels(score); | |
addXAxisLabels(year); | |
setSize(600, 450); | |
setBarWidth(100); | |
setSpaceWithinGroupsOfBars(20); | |
setDataStacked(true); | |
setTitle("Team Scores", BLACK, 16); | |
setGrid(100, 10, 3, 2); | |
setBackgroundFill(Fills.newSolidFill(ALICEBLUE)); | |
LinearGradientFill fill = Fills.newLinearGradientFill(0, LAVENDER, 100); | |
fill.addColorAndOffset(WHITE, 0); | |
setAreaFill(fill); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.charts4j; | |
import static com.googlecode.charts4j.Color.BLUEVIOLET; | |
import static com.googlecode.charts4j.Color.LIMEGREEN; | |
import static com.googlecode.charts4j.Color.ORANGERED; | |
import java.util.Arrays; | |
public class MyChartSample { | |
public static void main(String[] args) { | |
BarChartPlot team1 = Plots.newBarChartPlot(Data.newData(25, 43, 12, 30), BLUEVIOLET, "Team A"); | |
BarChartPlot team2 = Plots.newBarChartPlot(Data.newData(8, 35, 11, 5), ORANGERED, "Team B"); | |
BarChartPlot team3 = Plots.newBarChartPlot(Data.newData(10, 20, 30, 30), LIMEGREEN, "Team C"); | |
MyChart chart = new MyChart( | |
Arrays.asList(team1, team2, team3), | |
Arrays.asList("2002", "2003", "2004", "2005")); | |
System.out.println(chart.toURLString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment