public class ColorBlender
extends java.lang.Object
Provides access to the ColorBlender object.
This class allows you to easily obtain a gradient of colors between two selected color hues. By specifying a number of steps, developers may effortlessly create an even gradient of Color objects. Below is an example of how the ColorBlender object may be used to configure even gradient colors for series in a bar chart:
PopulateCarProduction(chart1);
chart1.getTitles().add(new TitleDockable("Vehicles Production by Type"));
chart1.setGallery(Gallery.BAR);
chart1.getData().setSeries(3);
ColorBlender cb;
cb = new ColorBlender(new java.awt.Color(173,216,230,255), new java.awt.Color(0,0,139,255), chart1.getData().getSeries());
int i;
i = 0;
for(; (i < (chart1.getData().getSeries())); (i)++)
{
chart1.getSeries().get(i).setColor(cb.nextColor());
}
public static void PopulateCarProduction(Chart chart1) { CarProduction[] production = new CarProduction[] { new CarProduction("Jan", 1760, 535, 695 ) , new CarProduction("Feb", 1849, 395, 688 ) , new CarProduction("Mar", 2831, 685, 1047 ) , new CarProduction("Apr", 2851, 984, 1652 ) , new CarProduction("May", 2961, 1579, 1889 ) , new CarProduction("Jun", 1519, 1539, 1766 ) , new CarProduction("Jul", 2633, 1489, 1361 ) , new CarProduction("Aug", 1140, 650, 874 ) , new CarProduction("Sep", 1626, 653, 693 ) , new CarProduction("Oct", 1478, 2236, 786 ) , new CarProduction("Nov", 1306, 1937, 599 ) , new CarProduction("Dec", 1607, 2138, 678 ) }; ObjectProvider objProvider = new ObjectProvider(production); chart1.getDataSourceSettings().setDataSource(objProvider); }
public static class CarProduction { private CarProduction(String month, int sedan, int coupe, int SUV) { this.setMonth(month); this.setSedan(sedan); this.setCoupe(coupe); this.setSUV(SUV); } private String privateMonth; public final String getMonth() { return privateMonth; } public final void setMonth(String value) { privateMonth = value; } private int privateSedan; public final int getSedan() { return privateSedan; } public final void setSedan(int value) { privateSedan = value; } private int privateCoupe; public final int getCoupe() { return privateCoupe; } public final void setCoupe(int value) { privateCoupe = value; } private int privateSUV; public final int getSUV() { return privateSUV; } public final void setSUV(int value) { privateSUV = value; } }
Constructor and Description |
---|
ColorBlender(java.awt.Color colorFrom,
java.awt.Color colorTo,
int steps)
Provides access to the ColorBlender object.
|
Modifier and Type | Method and Description |
---|---|
java.awt.Color |
getLevelColor(int level)
Description goes here
|
java.awt.Color |
nextColor()
Gets the next available gradient color from the blend.
|
void |
startBlending()
Resets the blender.
|
public ColorBlender(java.awt.Color colorFrom, java.awt.Color colorTo, int steps)
Provides access to the ColorBlender object.
colorFrom
- colorTo
- steps
- public java.awt.Color getLevelColor(int level)
level
- Obtains the color in the specified step.public java.awt.Color nextColor()
Gets the next available gradient color from the blend.
nextColor
is used to get the next available gradient color of the blender.
Below, the color of each series has been changed to different variations of blue using the ColorBlender
nextColor
method:
PopulateCarProduction(chart1);
chart1.getTitles().add(new TitleDockable("Vehicles Production by Type"));
chart1.setGallery(Gallery.BAR);
chart1.getData().setSeries(3);
ColorBlender cb;
cb = new ColorBlender(new java.awt.Color(173,216,230,255), new java.awt.Color(0,0,139,255), chart1.getData().getSeries());
int i;
i = 0;
for(; (i < (chart1.getData().getSeries())); (i)++)
{
chart1.getSeries().get(i).setColor(cb.nextColor());
}
public static void PopulateCarProduction(Chart chart1) { CarProduction[] production = new CarProduction[] { new CarProduction("Jan", 1760, 535, 695 ) , new CarProduction("Feb", 1849, 395, 688 ) , new CarProduction("Mar", 2831, 685, 1047 ) , new CarProduction("Apr", 2851, 984, 1652 ) , new CarProduction("May", 2961, 1579, 1889 ) , new CarProduction("Jun", 1519, 1539, 1766 ) , new CarProduction("Jul", 2633, 1489, 1361 ) , new CarProduction("Aug", 1140, 650, 874 ) , new CarProduction("Sep", 1626, 653, 693 ) , new CarProduction("Oct", 1478, 2236, 786 ) , new CarProduction("Nov", 1306, 1937, 599 ) , new CarProduction("Dec", 1607, 2138, 678 ) }; ObjectProvider objProvider = new ObjectProvider(production); chart1.getDataSourceSettings().setDataSource(objProvider); }
public static class CarProduction { private CarProduction(String month, int sedan, int coupe, int SUV) { this.setMonth(month); this.setSedan(sedan); this.setCoupe(coupe); this.setSUV(SUV); } private String privateMonth; public final String getMonth() { return privateMonth; } public final void setMonth(String value) { privateMonth = value; } private int privateSedan; public final int getSedan() { return privateSedan; } public final void setSedan(int value) { privateSedan = value; } private int privateCoupe; public final int getCoupe() { return privateCoupe; } public final void setCoupe(int value) { privateCoupe = value; } private int privateSUV; public final int getSUV() { return privateSUV; } public final void setSUV(int value) { privateSUV = value; } }
public void startBlending()
Resets the blender.
startBlending
can be used to reset the blender. This is useful if you need a few gradient values and then need to return to the original color of the blender.
To reset the blender and return to the original color of the blender:
ColorBlender cb; cb = new ColorBlender(new java.awt.Color(173,216,230,255), new java.awt.Color(0,0,139,255), 3); java.awt.Color color1; color1 = cb.NextColor(); java.awt.Color color2; color2 = cb.NextColor(); /* To reset the ColorBlender: *\/ cb.startBlending();
2014 Software FX, Inc. All Rights Reserved. Chart FX is a registered trademark of Software FX, Inc
All other names are trademarks or registered trademarks of their respective owners.