Java Code Examples for org.jfree.data.general.DefaultPieDataset#setValue()

The following examples show how to use org.jfree.data.general.DefaultPieDataset#setValue() . 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: PieDataSetCollector.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void buildDataset() {
  final DefaultPieDataset localPieDataset = (DefaultPieDataset) getDataSet();
  final Comparable seriesComparable = querySeriesValue( 0 );
  if ( seriesComparable == null ) {
    return;
  }

  final Object valueObject = getDataRow().get( getValueColumn() );
  final Number value = ( valueObject instanceof Number ) ? (Number) valueObject : null;
  final Number existingValue =
    CollectorFunctionUtil.queryExistingValueFromDataSet( localPieDataset, seriesComparable );
  if ( existingValue != null ) {
    if ( value != null ) {
      localPieDataset.setValue( seriesComparable, CollectorFunctionUtil.add( existingValue, value ) );
    }
  } else {
    localPieDataset.setValue( seriesComparable, value );
  }
}
 
Example 2
Source File: PieChartFXDemo1.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a sample dataset.
 * 
 * Source: http://www.bbc.co.uk/news/business-15489523
 *
 * @return A sample dataset.
 */
private static PieDataset createDataset() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Samsung", new Double(27.8));
    dataset.setValue("Others", new Double(55.3));
    dataset.setValue("Nokia", new Double(16.8));
    dataset.setValue("Apple", new Double(17.1));
    return dataset;
}
 
Example 3
Source File: JFreeChartTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Common test setup.
 */
@Before
public void setUp() {
    DefaultPieDataset data = new DefaultPieDataset();
    data.setValue("Java", new Double(43.2));
    data.setValue("Visual Basic", new Double(0.0));
    data.setValue("C/C++", new Double(17.5));
    this.pieChart = ChartFactory.createPieChart("Pie Chart", data);
}
 
Example 4
Source File: DefaultPieDatasetTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for the clear() method.
 */
public void testClear() {
    DefaultPieDataset d = new DefaultPieDataset();
    d.addChangeListener(this);
    // no event is generated if the dataset is already empty
    d.clear();
    assertNull(this.lastEvent);
    d.setValue("A", 1.0);
    assertEquals(1, d.getItemCount());
    this.lastEvent = null;
    d.clear();
    assertNotNull(this.lastEvent);
    assertEquals(0, d.getItemCount());
}
 
Example 5
Source File: StandardPieURLGeneratorTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test that the generated URL is as expected.
 */
@Test
public void testURL() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Alpha '1'", new Double(5.0));
    dataset.setValue("Beta", new Double(5.5));
    StandardPieURLGenerator g1 = new StandardPieURLGenerator(
            "chart.jsp", "category");
    String url = g1.generateURL(dataset, "Beta", 0);
    assertEquals("chart.jsp?category=Beta&pieIndex=0", url);
    url = g1.generateURL(dataset, "Alpha '1'", 0);
    assertEquals("chart.jsp?category=Alpha+%271%27&pieIndex=0", url);
}
 
Example 6
Source File: JFreeChartScriptlet.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void afterReportInit() throws JRScriptletException
{
	DefaultPieDataset dataset = new DefaultPieDataset();
	dataset.setValue("Java", 43.2d);
	dataset.setValue("Visual Basic", 10.0d);
	dataset.setValue("C/C++", 17.5d);
	dataset.setValue("PHP", 32.5d);
	dataset.setValue("Perl", 1.0d);

	JFreeChart chart = 
		ChartFactory.createPieChart3D(
			"Pie Chart 3D Demo 1",
			dataset,
			true,
			true,
			false
			);

	PiePlot3D plot = (PiePlot3D) chart.getPlot();
	plot.setStartAngle(290);
	plot.setDirection(Rotation.CLOCKWISE);
	plot.setForegroundAlpha(0.5f);
	plot.setNoDataMessage("No data to display");

	/*   */
	this.setVariableValue("Chart", new JCommonDrawableRendererImpl(chart));
}
 
Example 7
Source File: Prd4442Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testPieTooltip() throws Exception {
  DebugExpressionRuntime runtime = new DebugExpressionRuntime();
  FormulaPieTooltipGenerator gen = new FormulaPieTooltipGenerator( runtime, "=[chart::item]" );

  DefaultPieDataset dataSet = new DefaultPieDataset();
  dataSet.setValue( "Key-1", 5 );
  dataSet.setValue( "Key-2", 7 );
  dataSet.setValue( "Key-3", 10 );
  assertEquals( "5.0", gen.generateToolTip( dataSet, "Key-1" ) );
  assertEquals( "7.0", gen.generateToolTip( dataSet, "Key-2" ) );
  assertEquals( "10.0", gen.generateToolTip( dataSet, "Key-3" ) );
}
 
Example 8
Source File: PieChartFXDemo1.java    From jfree-fxdemos with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates a sample dataset.
 * 
 * Source: http://www.bbc.co.uk/news/business-15489523
 *
 * @return A sample dataset.
 */
private static PieDataset createDataset() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Samsung", new Double(27.8));
    dataset.setValue("Others", new Double(55.3));
    dataset.setValue("Nokia", new Double(16.8));
    dataset.setValue("Apple", new Double(17.1));
    return dataset;
}
 
Example 9
Source File: PieChart3DTest.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Tests that no exceptions are thrown when there is a <code>null</code>
 * value in the dataset.
 */
@Test
public void testNullValueInDataset() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Section 1", 10.0);
    dataset.setValue("Section 2", 11.0);
    dataset.setValue("Section 3", null);
    JFreeChart chart = createPieChart3D(dataset);
    BufferedImage image = new BufferedImage(200 , 100,
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
    g2.dispose();
    //FIXME we should really assert a value here
}
 
Example 10
Source File: MultiSimpleXmlChartDemo.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a sample dataset for the demo.
 *
 * @return A sample dataset.
 */
private PieDataset createSampleDataset()
{
  final DefaultPieDataset result = new DefaultPieDataset();
  // cheating: java has a higher chance to be the best language :)
  result.setValue("Java", new Integer((int) (Math.random() * 200)));
  result.setValue("Visual Basic", new Integer((int) (Math.random() * 50)));
  result.setValue("C/C++", new Integer((int) (Math.random() * 100)));
  result.setValue("PHP", new Integer((int) (Math.random() * 50)));
  result.setValue("Perl", new Integer((int) (Math.random() * 100)));
  return result;

}
 
Example 11
Source File: PieChartDemo1.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a sample dataset.
 * 
 * @return A sample dataset.
 */
private static PieDataset createDataset() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("One", new Double(43.2));
    dataset.setValue("Two", new Double(10.0));
    dataset.setValue("Three", new Double(27.5));
    dataset.setValue("Four", new Double(17.5));
    dataset.setValue("Five", new Double(11.0));
    dataset.setValue("Six", new Double(19.4));
    return dataset;        
}
 
Example 12
Source File: PieChart3DTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Common test setup.
 */
@Before
public void setUp() {
    // create a dataset...
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Java", new Double(43.2));
    dataset.setValue("Visual Basic", new Double(0.0));
    dataset.setValue("C/C++", new Double(17.5));
    this.pieChart = createPieChart3D(dataset);
}
 
Example 13
Source File: MultiAPIChartDemo.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a sample dataset for the demo.
 *
 * @return A sample dataset.
 */
private PieDataset createSampleDataset()
{
  final DefaultPieDataset result = new DefaultPieDataset();
  // cheating: java has a higher chance to be the best language :)
  result.setValue("Java", new Integer((int) (Math.random() * 200)));
  result.setValue("Visual Basic", new Integer((int) (Math.random() * 50)));
  result.setValue("C/C++", new Integer((int) (Math.random() * 100)));
  result.setValue("PHP", new Integer((int) (Math.random() * 50)));
  result.setValue("Perl", new Integer((int) (Math.random() * 100)));
  return result;

}
 
Example 14
Source File: PieChartDemo1.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a sample dataset.
 * 
 * Source: http://www.bbc.co.uk/news/business-15489523
 *
 * @return A sample dataset.
 */
private static PieDataset createDataset() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Samsung", new Double(27.8));
    dataset.setValue("Others", new Double(55.3));
    dataset.setValue("Nokia", new Double(16.8));
    dataset.setValue("Apple", new Double(17.1));
    return dataset;
}
 
Example 15
Source File: PieChartDemo1.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a sample dataset.
 * 
 * @return A sample dataset.
 */
private static PieDataset createDataset() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("One", new Double(43.2));
    dataset.setValue("Two", new Double(10.0));
    dataset.setValue("Three", new Double(27.5));
    dataset.setValue("Four", new Double(17.5));
    dataset.setValue("Five", new Double(11.0));
    dataset.setValue("Six", new Double(19.4));
    return dataset;        
}
 
Example 16
Source File: CategoryToPieDatasetTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * For datasets, the equals() method just checks keys and values.
 */
@Test
public void testEquals() {
    DefaultCategoryDataset underlying = new DefaultCategoryDataset();
    underlying.addValue(1.1, "R1", "C1");
    underlying.addValue(2.2, "R1", "C2");
    CategoryToPieDataset d1 = new CategoryToPieDataset(underlying,
            TableOrder.BY_COLUMN, 1);
    DefaultPieDataset d2 = new DefaultPieDataset();
    d2.setValue("R1", 2.2);
    assertTrue(d1.equals(d2));
}
 
Example 17
Source File: PieChartFXDemo1.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a sample dataset.
 * 
 * Source: http://www.bbc.co.uk/news/business-15489523
 *
 * @return A sample dataset.
 */
private static PieDataset createDataset() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Samsung", new Double(27.8));
    dataset.setValue("Others", new Double(55.3));
    dataset.setValue("Nokia", new Double(16.8));
    dataset.setValue("Apple", new Double(17.1));
    return dataset;
}
 
Example 18
Source File: PieChartDemo1.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a sample dataset.
 * 
 * Source: http://www.bbc.co.uk/news/business-15489523
 *
 * @return A sample dataset.
 */
private static PieDataset createDataset() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Samsung", new Double(27.8));
    dataset.setValue("Others", new Double(55.3));
    dataset.setValue("Nokia", new Double(16.8));
    dataset.setValue("Apple", new Double(17.1));
    return dataset;
}
 
Example 19
Source File: JFreeChartTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Serialize a pie chart, restore it, and check for equality.
 */
@Test
public void testSerialization1() {
    DefaultPieDataset data = new DefaultPieDataset();
    data.setValue("Type 1", 54.5);
    data.setValue("Type 2", 23.9);
    data.setValue("Type 3", 45.8);

    JFreeChart c1 = ChartFactory.createPieChart("Test", data);
    JFreeChart c2 = (JFreeChart) TestUtilities.serialised(c1);
    assertEquals(c1, c2);
    LegendTitle lt2 = c2.getLegend();
    assertSame(lt2.getSources()[0], c2.getPlot());
}
 
Example 20
Source File: CategoryToPieDatasetTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * For datasets, the equals() method just checks keys and values.
 */
@Test
public void testEquals() {
    DefaultCategoryDataset underlying = new DefaultCategoryDataset();
    underlying.addValue(1.1, "R1", "C1");
    underlying.addValue(2.2, "R1", "C2");
    CategoryToPieDataset d1 = new CategoryToPieDataset(underlying,
            TableOrder.BY_COLUMN, 1);
    DefaultPieDataset d2 = new DefaultPieDataset();
    d2.setValue("R1", 2.2);
    assertTrue(d1.equals(d2));
}