/* * (non-Javadoc) * * @see com.ibm.examples.chart.widget.chart.AbstractChartBuilder#buildXSeries() */ protected void buildXSeries() { data = adapter.getData(); int starting = 0; if (data.length > xSeriesTicks) starting = data.length - xSeriesTicks; x = new String[data.length - starting]; try { for (int j = starting, k = 0; j < data.length; j++, k++) x[k] = data[j][0].toString(); } catch (Exception e) { // e.printStackTrace(); } TextDataSet categoryValues = TextDataSetImpl.create(x); // NumberDataSet categoryValues = NumberDataSetImpl.create(new double[] { 0, 1, 2, 3 }); Series seCategory = SeriesImpl.create(); seCategory.setDataSet(categoryValues); // Apply the color palette SeriesDefinition sdX = SeriesDefinitionImpl.create(); sdX.getSeriesPalette().update(1); xAxis.getSeriesDefinitions().add(sdX); sdX.getSeries().add(seCategory); }
public void updateDataSet() { // Associate with Data Set try { data = adapter.getData(); int starting = 0; if (data.length > xSeriesTicks) starting = data.length - xSeriesTicks; x = new String[data.length - starting]; for (int j = starting, k = 0; j < data.length; j++, k++) x[k] = data[j][0].toString(); // X-Axis TextDataSet categoryValues = TextDataSetImpl.create(x); Axis xAxisPrimary = chart.getPrimaryBaseAxes()[0]; SeriesDefinition sdX = (SeriesDefinition) xAxisPrimary.getSeriesDefinitions().get(0); ((Series) sdX.getSeries().get(0)).setDataSet(categoryValues); // Y-Axis Axis yAxisPrimary = chart.getPrimaryOrthogonalAxis(xAxisPrimary); // chart.getOrthogonalAxes(xAxisPrimary, arg1) NumberDataSet orthoValuesDataSet1[] = new NumberDataSet[adapter.getSeriesCount()]; for (int i = 1; i <= adapter.getSeriesCount(); i++) { y = new Double[data.length - starting]; for (int j = starting, k = 0; j < data.length; j++, k++) { y[k] = NumberType.obj2num(data[j][i]).doubleValue(); if (max < y[k]) max = y[k]; } orthoValuesDataSet1[i - 1] = NumberDataSetImpl.create(y); SeriesDefinition sdY = (SeriesDefinition) yAxisPrimary.getSeriesDefinitions().get(i - 1); ((Series) sdY.getSeries().get(0)).setDataSet(orthoValuesDataSet1[i - 1]); } yAxis.getScale().setStep(max / 5); yAxis.getScale().setMax(NumberDataElementImpl.create(max)); } catch (Exception e) { // e.printStackTrace(); } }
public static final Chart createSeriesScript() { ChartWithAxes cwaBar = ChartWithAxesImpl.create(); cwaBar.setType("Bar Chart"); // $NON-NLS-1$ cwaBar.setSubType("Side-by-side"); // $NON-NLS-1$ cwaBar.setScript( "function beforeDrawSeries(series, renderer, scriptContext)" //$NON-NLS-1$ + "{series.getLabel().getCaption().getColor().set(12, 232, 182);}" //$NON-NLS-1$ ); cwaBar.getLegend().setVisible(false); cwaBar.getTitle().getLabel().getCaption().setValue("Chart with Series Script"); // $NON-NLS-1$ // X-Axis Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes()[0]; xAxisPrimary.setType(AxisType.TEXT_LITERAL); xAxisPrimary.getOrigin().setType(IntersectionType.VALUE_LITERAL); // Y-Axis Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis(xAxisPrimary); yAxisPrimary.getMajorGrid().setTickStyle(TickStyle.LEFT_LITERAL); yAxisPrimary.setType(AxisType.LINEAR_LITERAL); // Data Set TextDataSet categoryValues = TextDataSetImpl.create( new String[] { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ NumberDataSet orthoValues = NumberDataSetImpl.create(new double[] {8, 18, -15, -8, 10}); SampleData sd = DataFactory.eINSTANCE.createSampleData(); BaseSampleData sdBase = DataFactory.eINSTANCE.createBaseSampleData(); sdBase.setDataSetRepresentation(""); // $NON-NLS-1$ sd.getBaseSampleData().add(sdBase); OrthogonalSampleData sdOrthogonal = DataFactory.eINSTANCE.createOrthogonalSampleData(); sdOrthogonal.setDataSetRepresentation(""); // $NON-NLS-1$ sdOrthogonal.setSeriesDefinitionIndex(0); sd.getOrthogonalSampleData().add(sdOrthogonal); cwaBar.setSampleData(sd); // X-Series Series seCategory = SeriesImpl.create(); seCategory.setDataSet(categoryValues); SeriesDefinition sdX = SeriesDefinitionImpl.create(); xAxisPrimary.getSeriesDefinitions().add(sdX); sdX.getSeries().add(seCategory); // Y-Series BarSeries bs = (BarSeries) BarSeriesImpl.create(); bs.setDataSet(orthoValues); bs.getLabel().setVisible(true); SeriesDefinition sdY = SeriesDefinitionImpl.create(); yAxisPrimary.getSeriesDefinitions().add(sdY); sdY.getSeries().add(bs); return cwaBar; }