Package com.xeiam.xchart

Examples of com.xeiam.xchart.Chart


    double[] yData3 = new double[] { 50, 80, 90, 8, 1, 8, 9 };

    // double[] errdata = new double[] { 1, .699, .301, 2, 1, .699, 0.301 };
    double[] errdata = new double[] { 50, 20, 10, 52, 9, 2, 1 };

    Chart mychart = new Chart(1200, 800);

    mychart.getStyleManager().setYAxisLogarithmic(true); // set log or linear Y axis

    mychart.getStyleManager().setYAxisMin(.08);

    mychart.getStyleManager().setYAxisMax(1000);

    mychart.getStyleManager().setErrorBarsColor(Color.black);

    Series series1 = mychart.addSeries("Error bar test data", xData, yData1, errdata);

    Series series2 = mychart.addSeries("Y+error", xData, yData2);

    Series series3 = mychart.addSeries("Y-error", xData, yData3);

    series1.setLineStyle(SeriesLineStyle.SOLID);

    series1.setMarker(SeriesMarker.DIAMOND);
View Full Code Here


public class CSVChartColumns {

  public static void main(String[] args) throws Exception {

    // import chart from a folder containing CSV files
    Chart chart = CSVImporter.getChartFromCSVDir("./CSV/CSVChartColumns/", DataOrientation.Columns, 600, 600);

    CSVExporter.writeCSVColumns(chart.getSeriesMap().get("series1"), "./CSV/CSVChartColumnsExport/");

    // Show it
    new SwingWrapper(chart).displayChart();

  }
View Full Code Here

public class CSVChartRows {

  public static void main(String[] args) throws Exception {

    // import chart from a folder containing CSV files
    Chart chart = CSVImporter.getChartFromCSVDir("./CSV/CSVChartRows/", DataOrientation.Rows, 600, 400);

    CSVExporter.writeCSVRows(chart.getSeriesMap().get("series1"), "./CSV/CSVChartRowsExport/");

    // Show it
    new SwingWrapper(chart).displayChart();

  }
View Full Code Here

public class LineChart04 implements ExampleChart {

  public static void main(String[] args) {

    ExampleChart exampleChart = new LineChart04();
    Chart chart = exampleChart.getChart();
    new SwingWrapper(chart).displayChart();
  }
View Full Code Here

  @Override
  public Chart getChart() {

    // Create Chart
    Chart chart = new Chart(800, 600);

    // Customize Chart
    chart.setChartTitle("LineChart04");
    chart.setXAxisTitle("X");
    chart.setYAxisTitle("Y");
    chart.getStyleManager().setLegendVisible(false);

    for (int i = 0; i < 200; i++) {
      Series series = chart.addSeries("A" + i, new double[] { Math.random() / 1000, Math.random() / 1000 }, new double[] { Math.random() / -1000, Math.random() / -1000 });
      series.setLineColor(SeriesColor.BLUE);
      series.setLineStyle(SeriesLineStyle.SOLID);
      series.setMarker(SeriesMarker.CIRCLE);
      series.setMarkerColor(SeriesColor.BLUE);
    }
View Full Code Here

    QueryablePersistenceService persistenceService;

    int seriesCounter = 0;

    // Create Chart
    Chart chart = new ChartBuilder().width(width).height(height).build();
   
    // Define the time axis - the defaults are not very nice
    long period = (endTime.getTime() - startTime.getTime()) / 1000;
    String pattern = "HH:mm";
    if(period <= 600) {        // 10 minutes
      pattern = "mm:ss";
    }
    else if(period <= 86400) {    // 1 day
      pattern = "HH:mm";
    }
    else if(period <= 604800) {    // 1 week
      pattern = "EEE d";
    }
    else {
      pattern = "d MMM";
    }

    chart.getStyleManager().setDatePattern(pattern);
    chart.getStyleManager().setAxisTickLabelsFont(new Font("SansSerif", Font.PLAIN, 11));
    chart.getStyleManager().setChartPadding(5);
    chart.getStyleManager().setPlotBackgroundColor(new Color(254,254,254));
    chart.getStyleManager().setLegendBackgroundColor(new Color(224,224,224,160));
    chart.getStyleManager().setChartBackgroundColor(new Color(224,224,224,224));

    chart.getStyleManager().setLegendFont(new Font("SansSerif", Font.PLAIN, 10));
    chart.getStyleManager().setLegendSeriesLineLength(10);

    chart.getStyleManager().setXAxisMin(startTime.getTime());
    chart.getStyleManager().setXAxisMax(endTime.getTime());

    // If a persistence service is specified, find the provider
    persistenceService = null;
    if (service != null) {
      persistenceService = getPersistenceServices().get(service);
    } else {
      // Otherwise, just get the first service
      Set<Entry<String, QueryablePersistenceService>> serviceEntry = getPersistenceServices().entrySet();
      if(serviceEntry != null && serviceEntry.size() != 0)
        persistenceService = serviceEntry.iterator().next().getValue();
    }

    // Did we find a service?
    if (persistenceService == null) {
      throw new IllegalArgumentException("Persistence service not found '" + service + "'.");
    }

    // Loop through all the items
    if (items != null) {
      String[] itemNames = items.split(",");
      for (String itemName : itemNames) {
        Item item = itemUIRegistry.getItem(itemName);
        if(addItem(chart, persistenceService, startTime, endTime, item, seriesCounter))
          seriesCounter++;
      }
    }

    // Loop through all the groups and add each item from each group
    if (groups != null) {
      String[] groupNames = groups.split(",");
      for (String groupName : groupNames) {
        Item item = itemUIRegistry.getItem(groupName);
        if (item instanceof GroupItem) {
          GroupItem groupItem = (GroupItem) item;
          for (Item member : groupItem.getMembers()) {
            if(addItem(chart, persistenceService, startTime, endTime, member, seriesCounter))
              seriesCounter++;
          }
        } else {
          throw new ItemNotFoundException("Item '" + item.getName() + "' defined in groups is not a group.");
        }
      }
    }

    // If there are no series, render a blank chart
    if(seriesCounter == 0) {
      chart.getStyleManager().setLegendVisible(false);

      Collection<Date> xData = new ArrayList<Date>();
      Collection<Number> yData = new ArrayList<Number>();

      xData.add(startTime);
      yData.add(0);
      xData.add(endTime);
      yData.add(0);

      Series series = chart.addSeries("NONE", xData, yData);
      series.setMarker(SeriesMarker.NONE);
      series.setLineStyle(new BasicStroke(0f));
    }

    // Legend position (top-left or bottom-left) is dynamically selected based on the data
    // This won't be perfect, but it's a good compromise
    if(legendPosition < 0) {
      chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW);
    }
    else {
      chart.getStyleManager().setLegendPosition(LegendPosition.InsideSW);
    }

    // Write the chart as a PNG image
    BufferedImage lBufferedImage = new BufferedImage(chart.getWidth(), chart.getHeight(),
        BufferedImage.TYPE_INT_ARGB);
    Graphics2D lGraphics2D = lBufferedImage.createGraphics();
    chart.paint(lGraphics2D);
    return lBufferedImage;
  }
View Full Code Here

TOP

Related Classes of com.xeiam.xchart.Chart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.