Java Code Examples for org.jfree.chart.renderer.xy.XYLineAndShapeRenderer#setSeriesStroke()

The following examples show how to use org.jfree.chart.renderer.xy.XYLineAndShapeRenderer#setSeriesStroke() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PerformanceChart.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 6 votes vote down vote up
void display(String windowTitle) {
	//		 Create plot and show it
	JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, "No. of Fuzzy Inference Cycles", "Time (ms)", xyDataset, PlotOrientation.VERTICAL, true, true, true);
	chart.setBackgroundPaint(Color.white);
	final XYPlot xyPlot = chart.getXYPlot();
	final XYItemRenderer renderer = xyPlot.getRenderer();

	if( renderer instanceof XYLineAndShapeRenderer ) {
		final XYLineAndShapeRenderer rr = (XYLineAndShapeRenderer) renderer;
		//rr.setShapesVisible(true);
		// rr.setDefaultShapesFilled(false);
		rr.setSeriesStroke(1, new BasicStroke(1.2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 6f, 3f }, 0.0f));
		rr.setSeriesStroke(2, new BasicStroke(1.2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 10f, 6f }, 0.0f));
		rr.setSeriesStroke(3, new BasicStroke(1.2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 5f, 5f }, 0.0f));
		rr.setSeriesPaint(0, Color.BLACK);
		rr.setSeriesPaint(1, Color.GREEN);
		rr.setSeriesPaint(2, Color.RED);
		rr.setSeriesPaint(3, Color.BLUE);
		rr.setLinesVisible(true);
		//rr.setSeriesShape(0, ShapeUtilities.createDiamond(5));
	}

	PlotWindow.showIt(windowTitle, chart);
}
 
Example 2
Source File: BaseIndicatorBox.java    From TAcharting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void loadMVWAPIndicator(String key) throws XPathException{
    int timeFrameMVWAP = Integer.parseInt(parameter.getParameter(key, "Time Frame VWAP"));
    int timeFrameVWAP = Integer.parseInt(parameter.getParameter(key, "Time Frame MVWAP"));

    VWAPIndicator vwap = new VWAPIndicator(series.get(),timeFrameVWAP);
    MVWAPIndicator mvwap = new MVWAPIndicator(vwap,timeFrameMVWAP);

    List<Indicator> ilVwap = new ArrayList<>();
    List<String> nlVwap = new ArrayList<>();

    XYLineAndShapeRenderer wapRenderer = createRenderer(key, "Color MVWAP", "Shape MVWAP", "Stroke MVWAP");
    Color vwapColor = ConverterUtils.ColorAWTConverter.fromString(parameter.getParameter(key, "Color VWAP"));
    
    StrokeType vwapStroke = StrokeType.valueOf(parameter.getParameter(key, "Stroke VWAP"));
    ShapeType vwapShape = ShapeType.valueOf(parameter.getParameter(key, "Shape VWAP"));
    wapRenderer.setSeriesPaint(1, vwapColor);
    wapRenderer.setSeriesStroke(1, vwapStroke.stroke);
    wapRenderer.setSeriesShape(1, vwapShape.shape);
    IndicatorCategory category = parameter.getCategory(key);
    ChartType chartType = parameter.getChartType(key);
    ilVwap.add(mvwap);
    ilVwap.add(vwap);
    nlVwap.add(String.format("%s [%s] (%s)",getIdentifier(key), getID(key), timeFrameMVWAP));
    nlVwap.add(String.format("%s [%s] (%s)","VWAP", getID(key), timeFrameVWAP));
    addChartIndicator(key, ilVwap, nlVwap,"MVWAP/VWAP ",wapRenderer, chartType.toBoolean(), category);
}
 
Example 3
Source File: BaseIndicatorBox.java    From TAcharting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void loadAroonUP_DOWN(String key) throws XPathException{
    int arronUp = Integer.parseInt(parameter.getParameter(key, "Time Frame Up"));
    int arronDown = Integer.parseInt(parameter.getParameter(key, "Time Frame Down"));
    Color colorD = ConverterUtils.ColorAWTConverter.fromString(parameter.getParameter(key, "Color Down"));
    StrokeType strokeD = StrokeType.valueOf(parameter.getParameter(key, "Stroke Down"));
    ShapeType shapeD = ShapeType.valueOf(parameter.getParameter(key, "Shape Down"));
    ChartType chartType = parameter.getChartType(key);
    IndicatorCategory category = parameter.getCategory(key);

    List<Indicator> ilAroon = new ArrayList<>();
    List<String> nlAroon = new ArrayList<>();
    ilAroon.add(new AroonDownIndicator(series.get(), arronDown));
    ilAroon.add(new AroonUpIndicator(series.get(), arronUp));
    nlAroon.add("Aroon Down "+arronDown);
    nlAroon.add("Aroon Up "+arronUp);
    XYLineAndShapeRenderer arronUpDownRenderer = createRenderer(key, "Color Up", "Shape Up", "Stroke Up");

    arronUpDownRenderer.setSeriesPaint(1, colorD);
    arronUpDownRenderer.setSeriesStroke(1, strokeD.stroke);
    arronUpDownRenderer.setSeriesShape(1, shapeD.shape);

    addChartIndicator(key,
            ilAroon,
            nlAroon,String.format("%s [%s] (%s, %s)",getIdentifier(key), getID(key),arronUp, arronDown),
            arronUpDownRenderer,
            chartType.toBoolean(),
            category);
}
 
Example 4
Source File: RawSignalWindow.java    From ProtocolAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
public static void configurePanelLooks(JFreeChart chart, int selectionSeries) {
    TextTitle title = chart.getTitle(); // fix title
    Font titleFont = title.getFont();
    titleFont = titleFont.deriveFont(Font.PLAIN, (float) 14.0);
    title.setFont(titleFont);
    title.setPaint(Color.darkGray);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    XYLineAndShapeRenderer signalRenderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();
    signalRenderer.setSeriesStroke(selectionSeries, new BasicStroke(5f));
}
 
Example 5
Source File: ProfilePlotPanel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void configureRendererForCorrelativeData(XYLineAndShapeRenderer renderer) {
    renderer.setSeriesLinesVisible(1, false);
    renderer.setSeriesShapesVisible(1, true);
    renderer.setSeriesStroke(1, new BasicStroke(1.0f));
    renderer.setSeriesPaint(1, StatisticChartStyling.CORRELATIVE_POINT_PAINT);
    renderer.setSeriesFillPaint(1, StatisticChartStyling.CORRELATIVE_POINT_FILL_PAINT);
    renderer.setSeriesShape(1, StatisticChartStyling.CORRELATIVE_POINT_SHAPE);
}
 
Example 6
Source File: BaseIndicatorBox.java    From TAcharting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private XYLineAndShapeRenderer createRenderer(Paint p, Stroke s, Shape sh, boolean isShape){
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, isShape);
    if(isShape){
        renderer.setSeriesShape(0,sh);
    }
    renderer.setSeriesPaint(0,p);
    renderer.setSeriesStroke(0,s);
    return renderer;

}
 
Example 7
Source File: PulseDistributionTab.java    From ProtocolAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
public PulseDistributionTab(RawProtocolMessage message, CTabFolder chartFolder) {
    distributionData = createPulseDistributionPlot(message.m_PulseLengths);
    selectedIntervalSeries = new XYSeries("Selected Interval");
    distributionData.addSeries(selectedIntervalSeries);

    CTabItem distributionTab = new CTabItem(chartFolder, SWT.NONE);
    distributionTab.setText("Pulse length Distribution");

    // Create a Chart and a panel for pulse length distribution
    JFreeChart distributionChart = ChartFactory.createXYLineChart("Pulse Length Distribution", "Pulse Length (us)", "# Pulses", distributionData, PlotOrientation.VERTICAL, true, false, false);
    ChartPanel distributionChartPanel = new ChartPanel(distributionChart);
    RawSignalWindow.configurePanelLooks(distributionChart, 2);
    distributionChartPanel.setPreferredSize(new Dimension(700, 270));// 270

    // Make the mark line dashed, so we can see the space line when they overlap
    float pattern[] = {5.0f, 5.0f};
    BasicStroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.0f, pattern, 0.0f);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) distributionChart.getXYPlot().getRenderer();
    renderer.setSeriesStroke(0, stroke);

    // Create a ChartComposite on our tab for pulse distribution
    ChartComposite distributionFrame = new ChartComposite(chartFolder, SWT.NONE, distributionChart, true);
    distributionFrame.setHorizontalAxisTrace(false);
    distributionFrame.setVerticalAxisTrace(false);
    distributionFrame.setDisplayToolTips(true);
    GridData distributionGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    distributionGridData.grabExcessHorizontalSpace = true;
    distributionGridData.grabExcessVerticalSpace = false;
    distributionGridData.heightHint = 270;
    distributionFrame.setLayoutData(distributionGridData);
    distributionTab.setControl(distributionFrame);
}
 
Example 8
Source File: BaseIndicatorBox.java    From TAcharting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void loadAverageDirectionalMovementUP_DOWN(String key) throws XPathExpressionException {
    Color color1 = ConverterUtils.ColorAWTConverter.fromString(parameter.getParameter(key, "Color Up"));
    StrokeType stroke1 = StrokeType.valueOf(parameter.getParameter(key, "Stroke Up"));
    ShapeType shape1 = ShapeType.valueOf(parameter.getParameter(key,"Shape Up"));
    Color color2 = ConverterUtils.ColorAWTConverter.fromString(parameter.getParameter(key, "Color Down"));
    StrokeType stroke2 = StrokeType.valueOf(parameter.getParameter(key, "Stroke Down"));
    ShapeType shape2 = ShapeType.valueOf(parameter.getParameter(key,"Shape Down"));
    ChartType chartType = ChartType.valueOf(parameter.getParameter(key, "Chart Type"));
    IndicatorCategory category = parameter.getCategory(key);
    int timeFrameUp = Integer.parseInt(parameter.getParameter(key, "Time Frame Up"));
    int timeFrameDown = Integer.parseInt(parameter.getParameter(key, "Time Frame Up"));
    List<Indicator> ilAdx = new ArrayList<>();
    List<String> nlAdx = new ArrayList<>();

    ilAdx.add(new ADXIndicator(series.get(), timeFrameDown));
    ilAdx.add(new ADXIndicator(series.get(), timeFrameDown));
    nlAdx.add("ADX UP "+timeFrameUp);
    nlAdx.add("ADX Down "+timeFrameUp);
    XYLineAndShapeRenderer adxRenderer = new XYLineAndShapeRenderer();
    adxRenderer.setSeriesPaint(0, color1);
    adxRenderer.setSeriesStroke(0, stroke1.stroke);
    adxRenderer.setSeriesShape(0, shape1.shape);
    adxRenderer.setSeriesPaint(1, color2);
    adxRenderer.setSeriesStroke(1, stroke2.stroke);
    adxRenderer.setSeriesShape(1, shape2.shape);
    addChartIndicator(key,
            ilAdx,
            nlAdx,
            String.format("%s [%s] (%s, %s)", getIdentifier(key), getID(key), timeFrameUp, timeFrameDown ),
            adxRenderer,
            chartType.toBoolean(),
            category);

}
 
Example 9
Source File: BaseIndicatorBox.java    From TAcharting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void loadMACDIndicator(String key) throws XPathExpressionException {
    int timeFrameShort = Integer.parseInt(parameter.getParameter(key, "Time Frame Short"));
    int timeFrameLong = Integer.parseInt(parameter.getParameter(key, "Time Frame Long"));
    IndicatorCategory category = parameter.getCategory(key);
    ChartType chartType = parameter.getChartType(key);
    boolean signalLine = Boolean.valueOf(parameter.getParameter(key, "Add Signal Line"));
    XYLineAndShapeRenderer renderer = createRenderer(key, "Color", "Shape", "Stroke");
    MACDIndicator mcd = new MACDIndicator(closePriceIndicator.get(), timeFrameShort, timeFrameLong);
    if(!signalLine){
        addChartIndicator(key,
                mcd,
                String.format("%s [%s] (%s, %s)",getIdentifier(key), getID(key), timeFrameShort,timeFrameLong),
                renderer,
                chartType.toBoolean(),
                category);

    } else{
        int timeFrameSignal = Integer.parseInt(parameter.getParameter(key, "Time Frame Signal Line"));
        List<String> names = new ArrayList<>();
        List<Indicator> indicators = new ArrayList<>();
        indicators.add(mcd);
        indicators.add(new EMAIndicator(mcd, timeFrameSignal));
        names.add(String.format("%s [%s] (%s, %s)",getIdentifier(key), getID(key), timeFrameShort,timeFrameLong));
        names.add(String.format("Signal Line [%s] (%s)",getID(key),timeFrameSignal));
        Color color = ConverterUtils.ColorAWTConverter.fromString(parameter.getParameter(key, "Color Signal Line"));
        ShapeType shape = ShapeType.valueOf(parameter.getParameter(key, "Shape Signal Line"));
        StrokeType stroke = StrokeType.valueOf(parameter.getParameter(key, "Stroke Signal Line"));
        renderer.setSeriesPaint(1,color);
        renderer.setSeriesShape(1,shape.shape);
        renderer.setSeriesStroke(1, stroke.stroke);
        addChartIndicator(key,
                indicators,
                names,
                String.format("%s [%s] (%s, %s)",getIdentifier(key), getID(key), timeFrameShort,timeFrameLong),
                renderer,
                chartType.toBoolean(),
                category);
    }



}
 
Example 10
Source File: BaseIndicatorBox.java    From TAcharting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void loadKeltner(String key) throws XPathException{

        int timeFrame = Integer.parseInt(parameter.getParameter(key, "Time Frame"));
        double ratio = Double.valueOf(parameter.getParameter(key, "Ratio"));
        int atr = Integer.parseInt(parameter.getParameter(key, "Time Frame ATR"));
        Color colorU = ConverterUtils.ColorAWTConverter.fromString(parameter.getParameter(key, "Color Upper"));
        StrokeType strokeU = StrokeType.valueOf(parameter.getParameter(key, "Stroke Upper"));
        ShapeType shapeU = ShapeType.valueOf(parameter.getParameter(key,"Shape Upper"));
        Color colorL = ConverterUtils.ColorAWTConverter.fromString(parameter.getParameter(key, "Color Lower"));
        StrokeType strokeL = StrokeType.valueOf(parameter.getParameter(key, "Stroke Lower"));
        ShapeType shapeL = ShapeType.valueOf(parameter.getParameter(key,"Shape Lower"));
        ChartType chartType = ChartType.valueOf(parameter.getParameter(key, "Chart Type"));
        IndicatorCategory category = parameter.getCategory(key);

        XYLineAndShapeRenderer renderer = createRenderer(key, "Color Middle", "Shape Middle", "Stroke Middle");
        renderer.setSeriesStroke(1, strokeU.stroke);
        renderer.setSeriesStroke(2, strokeL.stroke);
        renderer.setSeriesShape(1, shapeU.shape);
        renderer.setSeriesShape(2, shapeL.shape);
        renderer.setSeriesPaint(1, colorU);
        renderer.setSeriesPaint(2, colorL);

        KeltnerChannelMiddleIndicator kcM = new KeltnerChannelMiddleIndicator(series.get(), timeFrame);
        KeltnerChannelUpperIndicator kcU = new KeltnerChannelUpperIndicator(kcM,ratio,atr);
        KeltnerChannelLowerIndicator kcL = new KeltnerChannelLowerIndicator(kcM,ratio,atr);

        List<Indicator> ilKelt = new ArrayList<>();
        List<String> nlKelt = new ArrayList<>();
        ilKelt.add(kcM);
        ilKelt.add(kcU);
        ilKelt.add(kcL);
        nlKelt.add("Keltner Middle");
        nlKelt.add("Keltner Upper");
        nlKelt.add("Keltner Lower");
        addChartIndicator(key,
                ilKelt,
                nlKelt,
                String.format("%s [%s] (%s, %s, %S)", getIdentifier(key), getID(key), timeFrame, ratio, atr),
                renderer,
                chartType.toBoolean(),
                category);
    }
 
Example 11
Source File: NumberLineChart.java    From EdgeSim with MIT License 4 votes vote down vote up
public NumberLineChart() {	
		this.collection = this.getCollection();
		initial();
		this.chart = ChartFactory.createXYLineChart(
				null, 
				"Request",
				"Hit Rate", 
				collection, 
				PlotOrientation.VERTICAL, 
				true, 
				true, 
				false
		);
		
		this.chart.getPlot().setBackgroundPaint(SystemColor.white);
		LegendTitle legend = chart.getLegend();
		legend.setPosition(RectangleEdge.RIGHT);
		legend.setHorizontalAlignment(HorizontalAlignment.LEFT);

		

		
		XYPlot plot = (XYPlot) chart.getPlot();		
		
		NumberAxis numberAxisX = (NumberAxis) chart.getXYPlot().getDomainAxis();
		numberAxisX.setTickUnit(new NumberTickUnit(500));
//		numberAxisX.setAutoRangeMinimumSize(0.1);
		numberAxisX.setAutoRangeIncludesZero(true);
		numberAxisX.setAxisLineVisible(false);
		numberAxisX.setTickMarkInsideLength(4f);
		numberAxisX.setTickMarkOutsideLength(0);

		
		
		NumberAxis numberAxisY = (NumberAxis) chart.getXYPlot().getRangeAxis();
		numberAxisY.setTickUnit(new NumberTickUnit(0.2));
		numberAxisY.setRangeWithMargins(0,1);
		numberAxisY.setAutoRangeIncludesZero(true);
		numberAxisY.setAxisLineVisible(false);
		numberAxisY.setTickMarkInsideLength(4f);
		numberAxisY.setTickMarkOutsideLength(0);
		// ����Y������Ϊ�ٷֱ�
		numberAxisY.setNumberFormatOverride(NumberFormat.getPercentInstance());
		
		
		
		XYItemRenderer xyitem = plot.getRenderer();   
        xyitem.setDefaultItemLabelsVisible(true);
//        ItemLabelsVisible(true);

		xyitem.setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
//        xyitem.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
//        xyitem.setBaseItemLabelFont(new Font("Dialog", 1, 12));
		xyitem.setDefaultItemLabelFont(new Font("Dialog", 1, 12));
        plot.setRenderer(xyitem);
		
		 	XYLineAndShapeRenderer renderer =  (XYLineAndShapeRenderer)plot.getRenderer();
			renderer.setDefaultItemLabelsVisible(true);
			renderer.setDefaultShapesVisible(true);
			renderer.setDrawOutlines(true);
			
			renderer.setSeriesOutlineStroke(0, new BasicStroke(5F));
			renderer.setSeriesOutlineStroke(1, new BasicStroke(5F));
			renderer.setSeriesOutlineStroke(2, new BasicStroke(5F));
			renderer.setSeriesOutlineStroke(3, new BasicStroke(5F));


			
			renderer.setSeriesPaint(0, Color.RED);
			renderer.setSeriesPaint(1, new Color(53,101,253));
			renderer.setSeriesPaint(2, new Color(0,161,59));//����ɫ
			renderer.setSeriesPaint(3, new Color(148,103,189));//��ɫ
			

			renderer.setSeriesStroke(0, new BasicStroke(4.0F));
			renderer.setSeriesStroke(1, new BasicStroke(4.0F));
			renderer.setSeriesStroke(2, new BasicStroke(4.0F));
			renderer.setSeriesStroke(3, new BasicStroke(4.0F));
			renderer.setSeriesStroke(4, new BasicStroke(2.0F));
			renderer.setSeriesStroke(5, new BasicStroke(2.0F));
		
			this.chartFrame = new ChartFrame("Line Chart", chart);
			chartFrame.pack();
			chartFrame.setSize(1600,1200);
			chartFrame.setLocation(300,200);
			chartFrame.setVisible(true);
	}
 
Example 12
Source File: BaseIndicatorBox.java    From TAcharting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void loadBollingerBands(String key) throws XPathException{
    List<Indicator> indicatorList = new ArrayList<>();
    List<String> namesList = new ArrayList<>();
    XYLineAndShapeRenderer bbRenderer = new XYLineAndShapeRenderer();
    int id = getID(key);

    int timeFrame = Integer.parseInt(parameter.getParameter(key,"Time Frame"));

    StandardDeviationIndicator sd = new StandardDeviationIndicator(closePriceIndicator.get(), timeFrame);
    EMAIndicator bollingerEMA = new EMAIndicator(closePriceIndicator.get(),timeFrame);
    Color color1 = ConverterUtils.ColorAWTConverter.fromString(parameter.getParameter(key, "Color Middle Band"));
    StrokeType stroke1 = StrokeType.valueOf(parameter.getParameter(key, "Stroke Middle Band"));
    ShapeType shape1 = ShapeType.valueOf(parameter.getParameter(key,"Shape Middle Band"));
    Color color2 = ConverterUtils.ColorAWTConverter.fromString(parameter.getParameter(key, "Color Upper Band"));
    StrokeType stroke2 = StrokeType.valueOf(parameter.getParameter(key, "Stroke Upper Band"));
    ShapeType shape2 = ShapeType.valueOf(parameter.getParameter(key,"Shape Upper Band"));
    Color color3 = ConverterUtils.ColorAWTConverter.fromString(parameter.getParameter(key, "Color Lower Band"));
    StrokeType stroke3 = StrokeType.valueOf(parameter.getParameter(key, "Stroke Lower Band"));
    ShapeType shape3 = ShapeType.valueOf(parameter.getParameter(key,"Shape Lower Band"));
    ChartType chartType = ChartType.valueOf(parameter.getParameter(key, "Chart Type"));
    IndicatorCategory category = parameter.getCategory(key);

    BollingerBandsMiddleIndicator bbm = new BollingerBandsMiddleIndicator(bollingerEMA);
    BollingerBandsUpperIndicator bbu = new BollingerBandsUpperIndicator(bbm,sd);
    BollingerBandsLowerIndicator bbl = new BollingerBandsLowerIndicator(bbm,sd);

    indicatorList.add(bbm);
    indicatorList.add(bbu);
    indicatorList.add(bbl);

    namesList.add("Middle Band"+ timeFrame);
    namesList.add("Upper Band ");
    namesList.add("Lower Band ");

    bbRenderer.setSeriesPaint(0, color1);
    bbRenderer.setSeriesStroke(0, stroke1.stroke);
    bbRenderer.setSeriesShape(0, shape1.shape);
    bbRenderer.setSeriesPaint(1, color2);
    bbRenderer.setSeriesStroke(1,stroke2.stroke);
    bbRenderer.setSeriesShape(1, shape2.shape);
    bbRenderer.setSeriesPaint(2, color3);
    bbRenderer.setSeriesStroke(2, stroke3.stroke);
    bbRenderer.setSeriesShape(2, shape3.shape);
    addChartIndicator(key,
            indicatorList,
            namesList,
            String.format("Bollinger Bands [%s] (%s)",id,timeFrame),
            bbRenderer,chartType.toBoolean(),
            category);
}
 
Example 13
Source File: LiquidityChartBuilder.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param forecast
 * @param settings (next days)
 * @return
 */
public JFreeChart createXYPlot(final LiquidityForecast forecast, final LiquidityForecastSettings settings)
{
  Validate.isTrue(settings.getNextDays() > 0 && settings.getNextDays() < 500);

  final LiquidityForecastCashFlow cashFlow = new LiquidityForecastCashFlow(forecast, settings.getNextDays());

  final TimeSeries accumulatedSeries = new TimeSeries(I18n.getString("plugins.liquidityplanning.forecast.dueDate"));
  final TimeSeries accumulatedSeriesExpected = new TimeSeries(
      PFUserContext.getLocalizedString("plugins.liquidityplanning.forecast.expected"));
  final TimeSeries worstCaseSeries = new TimeSeries(I18n.getString("plugins.liquidityplanning.forecast.worstCase"));
  double accumulatedExpected = settings.getStartAmount().doubleValue();
  double accumulated = accumulatedExpected;
  double worstCase = accumulated;

  final DayHolder dh = new DayHolder();
  final Date lower = dh.getDate();
  for (int i = 0; i < settings.getNextDays(); i++) {
    if (log.isDebugEnabled() == true) {
      log.debug("day: " + i + ", credits=" + cashFlow.getCredits()[i] + ", debits=" + cashFlow.getDebits()[i]);
    }
    final Day day = new Day(dh.getDayOfMonth(), dh.getMonth() + 1, dh.getYear());
    if (i > 0) {
      accumulated += cashFlow.getDebits()[i - 1].doubleValue() + cashFlow.getCredits()[i - 1].doubleValue();
      accumulatedExpected += cashFlow.getDebitsExpected()[i - 1].doubleValue() + cashFlow.getCreditsExpected()[i - 1].doubleValue();
      worstCase += cashFlow.getCredits()[i - 1].doubleValue();
    }
    accumulatedSeries.add(day, accumulated);
    accumulatedSeriesExpected.add(day, accumulatedExpected);
    worstCaseSeries.add(day, worstCase);
    dh.add(Calendar.DATE, 1);
  }
  dh.add(Calendar.DATE, -1);
  final XYChartBuilder cb = new XYChartBuilder(null, null, null, null, true);

  int counter = 0;

  final TimeSeriesCollection xyDataSeries = new TimeSeriesCollection();
  xyDataSeries.addSeries(accumulatedSeries);
  xyDataSeries.addSeries(worstCaseSeries);
  final XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, false);
  lineRenderer.setSeriesPaint(0, Color.BLACK);
  lineRenderer.setSeriesVisibleInLegend(0, true);
  lineRenderer.setSeriesPaint(1, cb.getGrayMarker());
  lineRenderer.setSeriesStroke(1, cb.getDashedStroke());
  lineRenderer.setSeriesVisibleInLegend(1, true);
  cb.setRenderer(counter, lineRenderer).setDataset(counter++, xyDataSeries);

  final TimeSeriesCollection accumulatedSet = new TimeSeriesCollection();
  accumulatedSet.addSeries(accumulatedSeriesExpected);
  final XYDifferenceRenderer diffRenderer = new XYDifferenceRenderer(cb.getGreenFill(), cb.getRedFill(), true);
  diffRenderer.setSeriesPaint(0, cb.getRedMarker());
  cb.setRenderer(counter, diffRenderer).setDataset(counter++, accumulatedSet)
  .setStrongStyle(diffRenderer, false, accumulatedSeriesExpected);
  diffRenderer.setSeriesVisibleInLegend(0, true);

  cb.setDateXAxis(true).setDateXAxisRange(lower, dh.getDate()).setYAxis(true, null);
  return cb.getChart();
}
 
Example 14
Source File: GraphPlot.java    From NSGA-II with MIT License 4 votes vote down vote up
public void configurePlotter(final String x_axis, final String y_axis) {
    
    JFreeChart xyLineChart = ChartFactory.createXYLineChart(GraphPlot.GRAPH_TITLE, x_axis, y_axis, GraphPlot.DATASET, PlotOrientation.VERTICAL, true, true, false);
    ChartPanel chartPanel = new ChartPanel(xyLineChart);
    
    chartPanel.setPreferredSize(new java.awt.Dimension(GraphPlot.DIMENSION_X, GraphPlot.DIMENSION_Y));
    
    final XYPlot plot = xyLineChart.getXYPlot();
    
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    
    renderer.setSeriesPaint(0, GraphPlot.COLOR);
    renderer.setSeriesStroke(0, new BasicStroke(GraphPlot.STROKE_THICKNESS));
    
    plot.setRenderer(renderer);
    setContentPane(chartPanel);
}
 
Example 15
Source File: AdminJFreeChartController.java    From Spring-MVC-Blueprints with MIT License 4 votes vote down vote up
private String createXYLineChart(HttpSession session, String title,
		String xtitle, String ytitle, int width, int height, String useMap,
		PrintWriter pw) {
	XYDataset xydataset = getXYDataset();
	String filename = "";

	JFreeChart chart = ChartFactory.createXYLineChart(title, xtitle,
			ytitle, xydataset, PlotOrientation.VERTICAL, true, true, true);
	chart.setTitle(new TextTitle(title, new Font("Calibri",
			Font.ITALIC, 12)));
	chart.getTitle().setFont(new Font("Calibri", Font.PLAIN, 12));
	chart.setBackgroundPaint(Color.white);

	/*
	 
	final XYPlot xyplot = (XYPlot) jfreechart.getPlot();
	xyplot.setBackgroundPaint(Color.lightGray);
	xyplot.setDomainGridlinePaint(Color.white);
	xyplot.setDomainGridlinesVisible(true);
	xyplot.setRangeGridlinePaint(Color.white);
	xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));

	final ValueAxis categoryAxis = xyplot.getDomainAxis();
	// categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
	categoryAxis.setLabelFont(new Font("Calibri", Font.TYPE1_FONT, 12));
	categoryAxis.setTickLabelFont(new Font("Calibri", Font.TYPE1_FONT, 12));

	NumberAxis numberAxis = (NumberAxis) xyplot.getRangeAxis();
	numberAxis.setLabelFont(new Font("Calibri", Font.TYPE1_FONT, 12));
	numberAxis.setTickLabelFont(new Font("Calibri", Font.TYPE1_FONT, 12));
	numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
	numberAxis.setAutoRangeIncludesZero(true);

	XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot
			.getRenderer();
	xylineandshaperenderer.setShapesVisible(true);
	xylineandshaperenderer.setShapesFilled(true);

	xylineandshaperenderer.setSeriesLinesVisible(0, false);
	xylineandshaperenderer.setSeriesShapesVisible(1, false);
	xyplot.setRenderer(xylineandshaperenderer);

	xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(2.0F, 1, 1,
			1.0F, new float[] { 10F, 6F }, 0.0F));
	xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(2.0F, 1, 1,
			1.0F, new float[] { 6F, 6F }, 0.0F));
	xylineandshaperenderer.setSeriesStroke(2, new BasicStroke(2.0F, 1, 1,
			1.0F, new float[] { 2.0F, 6F }, 0.0F));

	xylineandshaperenderer
			.setBaseItemLabelGenerator(new IntervalXYItemLabelGenerator(
					"({1},{2})", NumberFormat.getNumberInstance(),
					NumberFormat.getNumberInstance()));
	xylineandshaperenderer.setURLGenerator(new StandardXYURLGenerator(
			"/hrms/admin_charts", "seriesName", "itemName"));

	xylineandshaperenderer.setLegendTextFont(0, new Font("Calibri",
			Font.TYPE1_FONT, 12));
	xylineandshaperenderer.setLegendTextFont(1, new Font("Calibri",
			Font.TYPE1_FONT, 12));
	xylineandshaperenderer.setLegendTextFont(2, new Font("Calibri",
			Font.TYPE1_FONT, 12));
        */
	
      
      final XYPlot plot = chart.getXYPlot( );
      XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer( );
      renderer.setSeriesPaint( 0 , Color.RED );
      renderer.setSeriesPaint( 1 , Color.GREEN );
      renderer.setSeriesPaint( 2 , Color.YELLOW );
      renderer.setSeriesStroke( 0 , new BasicStroke( 4.0f ) );
      renderer.setSeriesStroke( 1 , new BasicStroke( 3.0f ) );
      renderer.setSeriesStroke( 2 , new BasicStroke( 2.0f ) );
      plot.setRenderer( renderer );
	ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

	try {
		filename = ServletUtilities.saveChartAsPNG(chart, width,
				height, info, session);
		ChartUtilities.writeImageMap(pw, useMap, info, false);
		pw.flush();
	} catch (IOException e) {
		e.printStackTrace();
	}
	return filename;
}
 
Example 16
Source File: ChartRendererFactory.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
private static void configureXYLineAndShapeRenderer(XYLineAndShapeRenderer renderer, ValueSource valueSource,
		PlotInstance plotInstance) {
	renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
	SeriesFormat seriesFormat = valueSource.getSeriesFormat();
	DimensionConfig domainConfig = valueSource.getDomainConfig();
	DimensionConfig colorDimensionConfig = plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(
			PlotDimension.COLOR);
	DimensionConfig shapeDimensionConfig = plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(
			PlotDimension.SHAPE);
	ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);

	int seriesCount = valueSourceData.getSeriesDataForAllGroupCells().groupCellCount();

	// Loop all series and set series format.
	// Format based on dimension configs will be set later on in initFormatDelegate().
	for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) {
		// configure linestyle
		if (seriesFormat.getLineStyle() == LineStyle.NONE) {
			renderer.setSeriesLinesVisible(seriesIdx, false);
		} else {
			renderer.setSeriesLinesVisible(seriesIdx, true);
			renderer.setSeriesStroke(seriesIdx, seriesFormat.getStroke(), false);
		}

		// configure series shape if necessary
		if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, shapeDimensionConfig)) {
			if (seriesFormat.getItemShape() != ItemShape.NONE) {
				renderer.setSeriesShapesVisible(seriesIdx, true);
				renderer.setSeriesShape(seriesIdx, seriesFormat.getItemShape().getShape());
			} else {
				renderer.setSeriesShapesVisible(seriesIdx, false);
			}
		}

		// configure series color if necessary
		if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) {
			Color itemColor = seriesFormat.getItemColor();
			renderer.setSeriesPaint(seriesIdx, itemColor);
			renderer.setSeriesFillPaint(seriesIdx, itemColor);
		}
		renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT);
		renderer.setUseOutlinePaint(true);
	}
}
 
Example 17
Source File: GraphPlot.java    From NSGA-II with MIT License 4 votes vote down vote up
public void configurePlotter(final String x_axis, final String y_axis) {
    
    JFreeChart xyLineChart = ChartFactory.createXYLineChart(GRAPH_TITLE, x_axis, y_axis, DATASET, PlotOrientation.VERTICAL, true, true, false);
    ChartPanel chartPanel = new ChartPanel(xyLineChart);
    
    chartPanel.setPreferredSize(new java.awt.Dimension(DIMENSION_X, DIMENSION_Y));
    
    final XYPlot plot = xyLineChart.getXYPlot();
    
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    
    renderer.setSeriesPaint(0, COLOR);
    renderer.setSeriesStroke(0, new BasicStroke(STROKE_THICKNESS));
    
    plot.setRenderer(renderer);
    setContentPane(chartPanel);
}
 
Example 18
Source File: TrafficLoadLineChart.java    From EdgeSim with MIT License 4 votes vote down vote up
public TrafficLoadLineChart() {	
		this.collection = this.getCollection();
		initial();
		this.chart = ChartFactory.createXYLineChart(
				null, 
				"Time Slice",
				"Traffic Load(100GB)", 
				collection, 
				PlotOrientation.VERTICAL, 
				true, 
				true, 
				false
		);
		this.chart.getPlot().setBackgroundPaint(SystemColor.white);
		LegendTitle legend = chart.getLegend();
		legend.setPosition(RectangleEdge.RIGHT);
		legend.setHorizontalAlignment(HorizontalAlignment.LEFT);

		

		
		XYPlot plot = (XYPlot) chart.getPlot();		
		
		NumberAxis numberAxisX = (NumberAxis) chart.getXYPlot().getDomainAxis();
		numberAxisX.setAutoRangeIncludesZero(false);
		
		numberAxisX.setAutoRangeMinimumSize(0.1);
		numberAxisX.setAxisLineVisible(false);
		numberAxisX.setTickMarkInsideLength(4f);
		numberAxisX.setTickMarkOutsideLength(0);
		
		
		NumberAxis numberAxisY = (NumberAxis) chart.getXYPlot().getRangeAxis();
		numberAxisY.setTickUnit(new NumberTickUnit(5));
		numberAxisY.setRangeWithMargins(0,40);
		numberAxisY.setAutoRangeIncludesZero(true);
		numberAxisY.setAxisLineVisible(false);
		numberAxisY.setTickMarkInsideLength(4f);
		numberAxisY.setTickMarkOutsideLength(0);
		numberAxisY.setNumberFormatOverride(NumberFormat.getNumberInstance());

		
		
		XYLineAndShapeRenderer renderer =  (XYLineAndShapeRenderer)plot.getRenderer();
		renderer.setDefaultItemLabelsVisible(true);
		renderer.setDefaultShapesVisible(true);
		renderer.setDrawOutlines(true);
			
		renderer.setSeriesOutlineStroke(0, new BasicStroke(5F));
		renderer.setSeriesOutlineStroke(1, new BasicStroke(5F));
		renderer.setSeriesOutlineStroke(2, new BasicStroke(5F));
		renderer.setSeriesOutlineStroke(3, new BasicStroke(5F));
		renderer.setSeriesOutlineStroke(4, new BasicStroke(5F));



			
		renderer.setSeriesPaint(1, Color.RED);
		renderer.setSeriesPaint(2, new Color(53,101,253));
		renderer.setSeriesPaint(3, new Color(0,161,59));//����ɫ
		renderer.setSeriesPaint(4, new Color(148,103,189));//��ɫ
		renderer.setSeriesPaint(0, new Color(255,125,11));//�ٻ�ɫ

			

		renderer.setSeriesStroke(0, new BasicStroke(4.0F));
		renderer.setSeriesStroke(1, new BasicStroke(4.0F));
		renderer.setSeriesStroke(2, new BasicStroke(4.0F));
		renderer.setSeriesStroke(3, new BasicStroke(4.0F));
		renderer.setSeriesStroke(4, new BasicStroke(2.0F));
		renderer.setSeriesStroke(5, new BasicStroke(2.0F));




//		renderer.setUseFillPaint(true);
		
		
		this.chartFrame = new ChartFrame("Line Chart", chart);
		chartFrame.pack();
		chartFrame.setSize(1600,1200);
		chartFrame.setLocation(300,200);
		chartFrame.setVisible(true);
	}
 
Example 19
Source File: AnomalyGraphGenerator.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a chart containing the current/baseline data (in that order) as well as markers for
 * each anomaly interval. timeGranularity and windowMillis are used to determine the date format
 * and spacing for tick marks on the domain (x) axis.
 */
public JFreeChart createChart(final XYDataset dataset, final String metric,
    final TimeGranularity timeGranularity, final long windowMillis,
    final Map<MergedAnomalyResultDTO, String> anomaliesWithLabels) {

  // create the chart...
  final JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // no chart title for email
                                                                    // image
      "Date (" + DEFAULT_TIME_ZONE.getID() + ")", // x axis label
      metric, // y axis label
      dataset, // data
      true, // include legend
      false, // tooltips - n/a if the chart will be saved as an img
      false // urls - n/a if the chart will be saved as an img
  );

  // get a reference to the plot for further customisation...
  final XYPlot plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setDomainGridlinesVisible(false);
  plot.setRangeGridlinesVisible(false);

  // dashboard webapp currently uses solid blue for current and dashed blue for baseline
  // (5/2/2016)
  final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
  renderer.setSeriesShapesVisible(0, false);
  renderer.setSeriesShapesVisible(1, false);
  renderer.setSeriesPaint(0, Color.BLUE);
  renderer.setSeriesPaint(1, Color.BLUE);
  // http://www.java2s.com/Code/Java/Chart/JFreeChartLineChartDemo5showingtheuseofacustomdrawingsupplier.htm
  // set baseline to be dashed
  renderer.setSeriesStroke(1,
      new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] {
          2.0f, 6.0f
      }, 0.0f));
  plot.setRenderer(renderer);

  DateAxis axis = (DateAxis) plot.getDomainAxis();
  DateTickUnit dateTickUnit = getDateTickUnit(timeGranularity, windowMillis);
  SimpleDateFormat dateFormat = getDateFormat(timeGranularity);
  axis.setDateFormatOverride(dateFormat);
  axis.setTickUnit(dateTickUnit);
  axis.setVerticalTickLabels(true);

  List<Marker> anomalyIntervals = getAnomalyIntervals(anomaliesWithLabels);
  for (Marker marker : anomalyIntervals) {
    plot.addDomainMarker(marker);
  }

  return chart;

}
 
Example 20
Source File: BaseLineChart.java    From EdgeSim with MIT License 4 votes vote down vote up
protected void generateLineChart(String xAisTitle, String yAisTitle,
									 NumberTickUnit xAisSpace, NumberTickUnit yAisSpace, double yaisMinValue, double yAisMaxValue,
									 XYSeriesCollection collection) {
		this.chart = ChartFactory.createXYLineChart(null, xAisTitle, yAisTitle,
				collection, PlotOrientation.VERTICAL, true, true, false);

		this.chart.getPlot().setBackgroundPaint(SystemColor.white);

		LegendTitle legend = chart.getLegend();
		legend.setPosition(RectangleEdge.RIGHT);
		legend.setHorizontalAlignment(HorizontalAlignment.LEFT);

		XYPlot plot = (XYPlot) chart.getPlot();
		NumberAxis numberAxisX = (NumberAxis) chart.getXYPlot().getDomainAxis();
		numberAxisX.setAutoRangeIncludesZero(false);

		numberAxisX.setTickUnit(xAisSpace);
		numberAxisX.setAxisLineVisible(false);
		numberAxisX.setTickMarkInsideLength(4f);
		numberAxisX.setTickMarkOutsideLength(0);

		NumberAxis numberAxisY = (NumberAxis) chart.getXYPlot().getRangeAxis();
		numberAxisY.setTickUnit(yAisSpace);
		numberAxisY.setRangeWithMargins(yaisMinValue, yAisMaxValue);
		numberAxisY.setAutoRangeIncludesZero(true);
		numberAxisY.setAxisLineVisible(false);
		numberAxisY.setTickMarkInsideLength(4f);
		numberAxisY.setTickMarkOutsideLength(0);
		numberAxisY.setNumberFormatOverride(NumberFormat.getNumberInstance());

		XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot
				.getRenderer();
//		renderer.setBaseItemLabelsVisible(true);
		renderer.setDefaultItemLabelsVisible(true);
		renderer.setDefaultShapesVisible(true);
//		renderer.setBaseShapesVisible(true);
		renderer.setDrawOutlines(true);

		renderer.setSeriesOutlineStroke(0, new BasicStroke(5F));
		renderer.setSeriesOutlineStroke(1, new BasicStroke(5F));
		renderer.setSeriesOutlineStroke(2, new BasicStroke(5F));
		renderer.setSeriesOutlineStroke(3, new BasicStroke(5F));
		renderer.setSeriesOutlineStroke(4, new BasicStroke(5F));

		renderer.setSeriesPaint(0, Color.RED);
		renderer.setSeriesPaint(1, Color.BLUE);
		renderer.setSeriesPaint(2, new Color(255, 125, 11));
		renderer.setSeriesPaint(3, new Color(0, 161, 59));
		renderer.setSeriesPaint(4, new Color(148, 103, 189));

		renderer.setSeriesStroke(0, new BasicStroke(4.0F));
		renderer.setSeriesStroke(1, new BasicStroke(4.0F));
		renderer.setSeriesStroke(2, new BasicStroke(4.0F));
		renderer.setSeriesStroke(3, new BasicStroke(4.0F));
		renderer.setSeriesStroke(4, new BasicStroke(2.0F));
		renderer.setSeriesStroke(5, new BasicStroke(2.0F));

		// renderer.setUseFillPaint(true);

		this.chartFrame = new ChartFrame("Line Chart", chart);
		chartFrame.pack();
		chartFrame.setSize(800, 600);
		chartFrame.setLocation(300, 200);
		chartFrame.setVisible(true);
	}