use of com.vaadin.addon.charts.model.XAxis in project charts by vaadin.
the class ColumnRangeResourceUsage method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart(ChartType.COLUMNRANGE);
Configuration conf = chart.getConfiguration();
conf.setTitle("Resource usage");
conf.getChart().setInverted(true);
XAxis xAxis = new XAxis();
xAxis.setCategories("Printer", "Coffee mahine");
conf.addxAxis(xAxis);
YAxis yAxis = new YAxis();
yAxis.setTitle("Time");
yAxis.setType(AxisType.DATETIME);
conf.addyAxis(yAxis);
Tooltip tooltip = new Tooltip();
tooltip.setFormatter("this.series.name +': '+ Highcharts.dateFormat('%H:%M', this.point.low) + ' - ' + Highcharts.dateFormat('%H:%M', this.point.high)");
conf.setTooltip(tooltip);
PlotOptionsColumnrange columnRange = new PlotOptionsColumnrange();
columnRange.setGrouping(false);
DataLabelsRange dataLabels = new DataLabelsRange(true);
dataLabels.setFormatter("this.y == this.point.low ? '' : this.series.name");
dataLabels.setInside(true);
dataLabels.setColor(new SolidColor("white"));
columnRange.setDataLabels(dataLabels);
conf.setPlotOptions(columnRange);
Calendar instance = Calendar.getInstance();
instance.set(Calendar.MILLISECOND, 0);
instance.set(2013, 6, 7, 12, 00, 00);
DataSeries a = new DataSeries();
a.setName("Team Alpha");
PlotOptionsColumnrange o = new PlotOptionsColumnrange();
o.setColor(new SolidColor(255, 60, 125, 0.8));
a.setPlotOptions(o);
DataSeries b = new DataSeries();
o = new PlotOptionsColumnrange();
o.setColor(new SolidColor(60, 125, 255, 0.8));
b.setPlotOptions(o);
b.setName("Team Beta");
DataSeriesItem item;
item = new DataSeriesItem();
item.setName("Printer");
item.setLow(instance.getTimeInMillis());
instance.roll(Calendar.HOUR_OF_DAY, 3);
item.setHigh(instance.getTimeInMillis());
a.add(item);
item = new DataSeriesItem();
item.setName("Printer");
instance.roll(Calendar.HOUR_OF_DAY, 1);
item.setLow(instance.getTimeInMillis());
instance.roll(Calendar.HOUR_OF_DAY, 1);
item.setHigh(instance.getTimeInMillis());
b.add(item);
instance.set(2013, 6, 7, 12, 00, 00);
item = new DataSeriesItem();
item.setName("Coffee mahine");
item.setLow(instance.getTimeInMillis());
instance.roll(Calendar.HOUR_OF_DAY, 2);
item.setHigh(instance.getTimeInMillis());
b.add(item);
item = new DataSeriesItem();
item.setName("Coffee mahine");
instance.roll(Calendar.HOUR_OF_DAY, -1);
item.setLow(instance.getTimeInMillis());
instance.roll(Calendar.HOUR_OF_DAY, 4);
item.setHigh(instance.getTimeInMillis());
a.add(item);
conf.setSeries(a, b);
return chart;
}
use of com.vaadin.addon.charts.model.XAxis in project charts by vaadin.
the class BasicLineWithTickCount method getChart.
@Override
protected Component getChart() {
VerticalLayout layout = new VerticalLayout();
layout.setSpacing(false);
layout.setMargin(false);
final Chart chart = new Chart(ChartType.LINE);
chart.setHeight("400px");
chart.setWidth("100%");
Configuration configuration = chart.getConfiguration();
configuration.getTitle().setText("Monthly Average Temperature");
configuration.getSubTitle().setText("Source: WorldClimate.com");
configuration.getxAxis().setCategories("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
XAxis xAxis = configuration.getxAxis();
Labels xLabels = new Labels();
xLabels.setAutoRotation(new Number[] { -10, -20, -30, -40, 50, -60, -70, -80, -90 });
xAxis.setLabels(xLabels);
final YAxis yAxis = configuration.getyAxis();
yAxis.setTickAmount(10);
ListSeries ls = new ListSeries();
ls.setName("Tokyo");
ls.setData(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6);
configuration.addSeries(ls);
ls = new ListSeries();
ls.setName("New York");
ls.setData(-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5);
configuration.addSeries(ls);
layout.addComponent(chart);
final Slider slider = new Slider("Tick count (2 - 16)", 2, 16);
slider.setWidth("200px");
slider.setValue(10d);
layout.addComponent(slider);
layout.addComponent(new Button("Set max amount", new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
slider.setValue(16d);
}
}));
slider.addValueChangeListener(event -> {
double newValue = slider.getValue();
yAxis.setTickAmount(newValue);
chart.drawChart();
});
return layout;
}
use of com.vaadin.addon.charts.model.XAxis in project charts by vaadin.
the class Basic3DColumnWithGradientBackground method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart(ChartType.COLUMN);
Configuration conf = chart.getConfiguration();
conf.setTitle("Monthly Average Rainfall");
conf.setSubTitle("Source: WorldClimate.com");
XAxis x = new XAxis();
x.setCategories(new String[] { "Jan", "Feb", "Mar", "Apr" });
conf.addxAxis(x);
YAxis y = new YAxis();
y.setMin(0);
y.setTitle("Rainfall (mm)");
conf.addyAxis(y);
Tooltip tooltip = new Tooltip();
tooltip.setFormatter("this.x +': '+ this.y +' mm'");
conf.setTooltip(tooltip);
PlotOptionsColumn plot = new PlotOptionsColumn();
plot.setPointPadding(0.2);
plot.setBorderWidth(0);
plot.setGroupZPadding(10);
conf.setPlotOptions(plot);
Options3d options3d = new Options3d();
options3d.setEnabled(true);
options3d.setAlpha(5);
options3d.setBeta(30);
options3d.setDepth(100);
options3d.setViewDistance(200);
Frame frame = new Frame();
options3d.setFrame(frame);
frame.setBack(new Back());
GradientColor c = GradientColor.createLinear(0, 0, 1, 0);
c.addColorStop(0, SolidColor.RED);
c.addColorStop(1, SolidColor.AQUAMARINE);
frame.getBack().setColor(c);
frame.getBack().setSize(1);
conf.getChart().setOptions3d(options3d);
conf.addSeries(new ListSeries("Tokyo", 49.9, 71.5, 106.4, 129.2));
chart.drawChart(conf);
return chart;
}
use of com.vaadin.addon.charts.model.XAxis in project charts by vaadin.
the class BoxPlotExample method getChart.
@Override
protected Component getChart() {
chart = new Chart();
chart.getConfiguration().setTitle("Box Plot Example");
Legend legend = new Legend();
legend.setEnabled(false);
chart.getConfiguration().setLegend(legend);
XAxis xaxis = chart.getConfiguration().getxAxis();
xaxis.setTitle("Experiment No.");
xaxis.setCategories("1", "2", "3", "4", "5");
YAxis yAxis = chart.getConfiguration().getyAxis();
yAxis.setTitle("Observations");
PlotLine plotLine = new PlotLine();
plotLine.setColor(new SolidColor("red"));
plotLine.setValue(932);
plotLine.setWidth(1);
plotLine.setZIndex(0);
plotLine.setDashStyle(DashStyle.DASHDOT);
Label label = new Label("Theoretical mean: 932");
label.setAlign(HorizontalAlign.CENTER);
Style style = new Style();
style.setColor(new SolidColor("gray"));
label.setStyle(style);
plotLine.setLabel(label);
PlotLine plotLine2 = new PlotLine();
plotLine2.setColor(new SolidColor("blue"));
plotLine2.setValue(800);
plotLine2.setWidth(1);
plotLine2.setZIndex(500);
plotLine2.setDashStyle(DashStyle.SHORTDASHDOTDOT);
Label label2 = new Label("Second plotline: 800");
label2.setAlign(HorizontalAlign.CENTER);
Style style2 = new Style();
style2.setColor(new SolidColor("gray"));
label2.setStyle(style2);
plotLine2.setLabel(label2);
yAxis.setPlotLines(plotLine, plotLine2);
observations = new DataSeries();
observations.setName("Observations");
// Add PlotBoxItems contain all fields relevant for plot box chart
observations.add(new BoxPlotItem(760, 801, 848, 895, 965));
// Example with no arg constructor
BoxPlotItem plotBoxItem = new BoxPlotItem();
plotBoxItem.setLow(733);
plotBoxItem.setLowerQuartile(853);
plotBoxItem.setMedian(939);
plotBoxItem.setUpperQuartile(980);
plotBoxItem.setHigh(1080);
observations.add(plotBoxItem);
observations.add(new BoxPlotItem(714, 762, 817, 870, 918));
observations.add(new BoxPlotItem(724, 802, 806, 871, 950));
observations.add(new BoxPlotItem(834, 836, 864, 882, 910));
observations.setPlotOptions(getPlotBoxOptions());
chart.getConfiguration().addSeries(observations);
return chart;
}
use of com.vaadin.addon.charts.model.XAxis in project charts by vaadin.
the class ChartTypes method chartTypesPolygon.
public void chartTypesPolygon() {
Chart chart = new Chart();
Configuration conf = chart.getConfiguration();
conf.setTitle("Height vs Weight");
XAxis xAxis = conf.getxAxis();
xAxis.setStartOnTick(true);
xAxis.setEndOnTick(true);
xAxis.setShowLastLabel(true);
xAxis.setTitle("Height (cm)");
YAxis yAxis = conf.getyAxis();
yAxis.setTitle("Weight (kg)");
PlotOptionsScatter optionsScatter = new PlotOptionsScatter();
DataSeries scatter = new DataSeries();
scatter.setPlotOptions(optionsScatter);
scatter.setName("Observations");
scatter.add(new DataSeriesItem(160, 67));
scatter.add(new DataSeriesItem(180, 75));
conf.addSeries(scatter);
DataSeries polygon = new DataSeries();
PlotOptionsPolygon optionsPolygon = new PlotOptionsPolygon();
optionsPolygon.setEnableMouseTracking(false);
polygon.setPlotOptions(optionsPolygon);
polygon.setName("Target");
polygon.add(new DataSeriesItem(153, 42));
polygon.add(new DataSeriesItem(149, 46));
polygon.add(new DataSeriesItem(173, 52));
polygon.add(new DataSeriesItem(166, 45));
conf.addSeries(polygon);
}
Aggregations