use of com.vaadin.addon.charts.model.YAxis in project charts by vaadin.
the class VUMeter method getChart.
@Override
protected Component getChart() {
final Chart chart = new Chart();
chart.setWidth("600px");
chart.setHeight("200px");
GradientColor gradient = GradientColor.createLinear(0, 0, 0, 1);
gradient.addColorStop(0, new SolidColor("#FFF4C6"));
gradient.addColorStop(0.3, new SolidColor("#FFFFFF"));
gradient.addColorStop(1, new SolidColor("#FFF4C6"));
final Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.GAUGE);
configuration.getChart().setPlotBackgroundColor(gradient);
configuration.getChart().setPlotBackgroundImage(null);
configuration.getChart().setPlotBorderWidth(1);
configuration.setTitle("VU meter");
Pane pane1 = new Pane(-45, 45);
Pane pane2 = new Pane(-45, 45);
pane1.setBackground(new Background[] {});
pane2.setBackground(new Background[] {});
pane1.setCenter("25%", "145%");
pane2.setCenter("75%", "145%");
pane1.setSize("300px");
pane2.setSize("300");
configuration.addPane(pane1);
configuration.addPane(pane2);
PlotBand plotBand1 = new PlotBand(0, 6, new SolidColor("#C02316"));
plotBand1.setInnerRadius("100%");
plotBand1.setOuterRadius("105%");
PlotBand plotBand2 = new PlotBand(0, 6, new SolidColor("#C02316"));
plotBand2.setInnerRadius("100%");
plotBand2.setOuterRadius("105%");
YAxis yAxis = new YAxis();
yAxis.setPane(pane1);
yAxis.setTitle("VU<br/><span style=\"font-size:8px\">Channel A</span>");
yAxis.getTitle().setY(-40);
yAxis.setMin(-20);
yAxis.setMax(6);
yAxis.setTickPosition(TickPosition.OUTSIDE);
yAxis.setMinorTickPosition(TickPosition.OUTSIDE);
Labels labels = new Labels();
labels.setDistance(20);
labels.setRotationPerpendicular();
yAxis.setLabels(labels);
yAxis.setPlotBands(plotBand1);
YAxis yAxis2 = new YAxis();
yAxis2.setPane(pane2);
yAxis2.setTitle("VU<br/><span style=\"font-size:8px\">Channel B</span>");
yAxis2.getTitle().setY(-40);
yAxis2.setMin(-20);
yAxis2.setMax(6);
yAxis2.setTickPosition(TickPosition.OUTSIDE);
yAxis2.setMinorTickPosition(TickPosition.OUTSIDE);
labels = new Labels();
labels.setDistance(20);
labels.setRotationPerpendicular();
yAxis2.setLabels(labels);
yAxis2.setPlotBands(plotBand2);
configuration.addyAxis(yAxis);
configuration.addyAxis(yAxis2);
PlotOptionsGauge gauge = new PlotOptionsGauge();
gauge.setDataLabels(new DataLabels(false));
gauge.setDial(new Dial());
gauge.getDial().setRadius("100%");
configuration.setPlotOptions(gauge);
final ListSeries series1 = new ListSeries(-20);
final ListSeries series2 = new ListSeries(-20);
series1.setyAxis(0);
series2.setyAxis(1);
configuration.setSeries(series1, series2);
runWhileAttached(chart, new Runnable() {
final Random r = new Random(0);
@Override
public void run() {
double left = series1.getData()[0].doubleValue();
double inc = (r.nextDouble() - 0.5) * 3;
double leftVal = left + inc;
double rightVal = leftVal + inc / 3;
if (leftVal < -20 || leftVal > 6) {
leftVal = left - inc;
}
if (rightVal < -20 || rightVal > 6) {
rightVal = leftVal;
}
series1.updatePoint(0, leftVal);
series2.updatePoint(0, rightVal);
}
}, 500, 12000);
chart.drawChart(configuration);
return chart;
}
use of com.vaadin.addon.charts.model.YAxis in project charts by vaadin.
the class ServerSideEvents method getChart.
@Override
protected Component getChart() {
eventDetails.setId("eventDetails");
lastEvent.setId("lastEvent");
historyLayout.setId("history");
chart = new Chart();
chart.setId("chart");
chart.setWidth("500px");
final Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.SCATTER);
configuration.getTitle().setText("Test server side events.");
configuration.getSubTitle().setText("When an event occurs, the details are shown below the chart");
configuration.setExporting(true);
configuration.getChart().setAnimation(false);
configuration.getChart().setZoomType(ZoomType.XY);
XAxis xAxis = configuration.getxAxis();
xAxis.setMinPadding(0.2);
xAxis.setMaxPadding(0.2);
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle(new AxisTitle("Value"));
PlotLine plotline = new PlotLine();
plotline.setValue(0);
plotline.setWidth(1);
plotline.setColor(new SolidColor("#808080"));
yAxis.setPlotLines(new PlotLine[] { plotline });
yAxis.setMinPadding(0.2);
yAxis.setMaxPadding(0.2);
YAxis yAxis1 = new YAxis();
yAxis1.setTitle("Another axis");
yAxis1.setOpposite(true);
configuration.addyAxis(yAxis1);
PlotOptionsSeries opt = new PlotOptionsSeries();
opt.setLineWidth(1);
opt.setShowCheckbox(true);
opt.setAllowPointSelect(true);
configuration.setPlotOptions(opt);
configuration.setTooltip(new Tooltip(false));
final DataSeries series1 = createDataSeries(0);
final DataSeries series2 = createDataSeries(20);
DataSeries series3 = createDataSeries(100);
series3.get(0).setY(105);
series3.get(3).setY(95);
series3.setName("Another axis");
series3.setyAxis(1);
firstDataPoint = series1.get(0);
firstDataPoint.setSelected(true);
configuration.setSeries(series1, series2, series3);
chart.drawChart(configuration);
final Layout toggles = createControls();
Layout eventListeners = addEventListeners();
chart.setSeriesVisibilityTogglingDisabled(false);
visibilityToggling.setValue(false);
lastEvent.setCaption("Last event");
eventDetails.setCaption("Details");
historyLayout.setCaption("History");
VerticalLayout layout = new VerticalLayout();
layout.setSpacing(true);
layout.addComponent(toggles);
HorizontalLayout chartAndListeners = new HorizontalLayout(chart, eventListeners);
chartAndListeners.setSizeUndefined();
chartAndListeners.setSpacing(true);
layout.addComponent(chartAndListeners);
layout.addComponent(lastEvent);
layout.addComponent(eventDetails);
layout.addComponent(historyLayout);
return layout;
}
use of com.vaadin.addon.charts.model.YAxis in project charts by vaadin.
the class BasicLineGettingMousePointerPosition method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart();
chart.setId("chart");
Color[] colors = getThemeColors();
Configuration conf = chart.getConfiguration();
conf.getChart().setZoomType(ZoomType.XY);
conf.setTitle("Average Monthly Temperature and Rainfall in Tokyo");
conf.setSubTitle("Source: WorldClimate.com");
XAxis x = new XAxis();
x.setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
conf.addxAxis(x);
YAxis primary = new YAxis();
primary.setTitle("Temperature");
Style style = new Style();
style.setColor(colors[0]);
primary.getTitle().setStyle(style);
conf.addyAxis(primary);
YAxis snd = new YAxis();
snd.setTitle("Rainfall");
snd.setOpposite(true);
style = new Style();
style.setColor(colors[1]);
snd.getTitle().setStyle(style);
conf.addyAxis(snd);
Tooltip tooltip = new Tooltip(false);
conf.setTooltip(tooltip);
Legend legend = new Legend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setAlign(HorizontalAlign.LEFT);
legend.setX(120);
legend.setVerticalAlign(VerticalAlign.TOP);
legend.setY(100);
legend.setFloating(true);
legend.setBackgroundColor(new SolidColor("#FFFFFF"));
conf.setLegend(legend);
DataSeries series = new DataSeries();
series.setPlotOptions(new PlotOptionsColumn());
series.setName("Rainfall");
series.setData(49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4);
series.setyAxis(1);
conf.addSeries(series);
series = new DataSeries();
PlotOptionsSpline plotOptions = new PlotOptionsSpline();
series.setPlotOptions(plotOptions);
series.setName("Temperature");
series.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);
conf.addSeries(series);
chart.addPointClickListener(new PointClickListener() {
@Override
public void onClick(PointClickEvent event) {
Window win = new Window("PointClickEvent window");
win.setContent(new Label("Browser client area coordinates: point X:" + event.getAbsoluteX() + " Y:" + event.getAbsoluteY()));
win.setPositionX(event.getAbsoluteX());
win.setPositionY(event.getAbsoluteY());
getUI().addWindow(win);
}
});
chart.addChartClickListener(new ChartClickListener() {
@Override
public void onClick(ChartClickEvent event) {
Window win = new Window("Chart Click Event Window");
win.setContent(new Label("Browser client area coordinates: point X:" + event.getAbsoluteX() + " Y:" + event.getAbsoluteY()));
win.setPositionX(event.getAbsoluteX());
win.setPositionY(event.getAbsoluteY());
getUI().addWindow(win);
}
});
return chart;
}
use of com.vaadin.addon.charts.model.YAxis in project charts by vaadin.
the class LogarithmicAxis method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart();
chart.setHeight("450px");
chart.setWidth("100%");
Configuration configuration = chart.getConfiguration();
configuration.getTitle().setText("Logarithmic axis demo");
configuration.getxAxis().setTickInterval(1);
YAxis yAxis = configuration.getyAxis();
yAxis.setType(AxisType.LOGARITHMIC);
yAxis.setMinorTickInterval("0.1");
configuration.getTooltip().setHeaderFormat("<b>{series.name}</b><br />");
configuration.getTooltip().setPointFormat("x = {point.x}, y = {point.y}");
PlotOptionsLine plotOptions = new PlotOptionsLine();
plotOptions.setPointStart(1);
configuration.setPlotOptions(plotOptions);
ListSeries ls = new ListSeries(1, 2, 4, 8, 16, 32, 64, 128, 256, 512);
configuration.setSeries(ls);
chart.drawChart(configuration);
return chart;
}
use of com.vaadin.addon.charts.model.YAxis in project charts by vaadin.
the class SplineInverted method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart();
chart.setWidth("500px");
Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.SPLINE);
configuration.getChart().setInverted(true);
configuration.getTitle().setText("Atmosphere Temperature by Altitude");
configuration.getSubTitle().setText("According to the Standard Atmosphere Model");
XAxis xAxis = configuration.getxAxis();
xAxis.setReversed(false);
xAxis.setTitle(new AxisTitle("Altitude"));
Labels labels = new Labels();
labels.setFormatter("this.value + 'km'");
labels.setEnabled(true);
xAxis.setLabels(labels);
xAxis.setMaxPadding(0.05);
xAxis.setShowLastLabel(true);
YAxis yAxis = configuration.getyAxis();
yAxis.setLineWidth(2);
yAxis.setTitle(new AxisTitle("Temperature"));
yAxis.getTitle().setAlign(VerticalAlign.MIDDLE);
Labels labelsy = new Labels();
labelsy.setEnabled(true);
labelsy.setFormatter("this.value + '°'");
yAxis.setLabels(labelsy);
configuration.getTooltip().setFormatter("this.x +' km: '+this.y +'°C'");
PlotOptionsSpline plotOptions = new PlotOptionsSpline();
plotOptions.setMarker(new Marker(true));
configuration.setPlotOptions(plotOptions);
Legend legend = configuration.getLegend();
legend.setEnabled(false);
DataSeries series = new DataSeries();
series.setPlotOptions(new PlotOptionsSpline());
series.setName("Temperature");
series.addData(new Number[][] { { 0, 15 }, { 10, -50 }, { 20, -56.5 }, { 30, -46.5 }, { 40, -22.1 }, { 50, -2.5 }, { 60, -27.7 }, { 70, -55.7 }, { 80, -76.5 } });
configuration.setSeries(series);
chart.drawChart(configuration);
return chart;
}
Aggregations