ColorGenerator colorGen = new ColorGenerator(); // We need to assign colors to the pie slices automatically, so we use a // class that cycles through colors. See this class defined below. nData = new StringTokenizer(dataNumber, “,”); lData = new StringTokenizer(dataLabel, “,”); // We used our preformatted column data, and need to break it down to the // elements. We use the StringTokenizer to break the column string data // individual down by commas we inserted when we created the data. // We assume that dataNumber and dataLabel have the same number of // elements since we just generated them from the getData method. while(nData.hasMoreTokens()) { // Loop through the dataNumber and dataLabel and build the slice data: // ( 1234, darkBlue, “Label” ). This is what the pie chart class expects, // so we must parse our data and put it in this format. SliceData += “(”+nData.nextToken() + “, ” + colorGen.next() + “, ‘” + lData.nextToken() + “‘, green)”; System.out.println(SliceData); if (nData.hasMoreTokens()) {SliceData += “, “;} } try { // We already instantiated the pie chart // class(NFPieChartAPP) at the top of the applet. pie.init(); pie.start(); // Initialize and start the pie chart class. pie.loadParams( “Background=(black, RAISED, 4);”+ “Header=(’Cost Information (millions)’);”+ “LabelPos=0.7;”+ “DwellLabel = ('’, black, ‘TimesRoman’, 16);”+ “Legend = (’Legend’, black);”+ “LegendBox = (white, RAISED, 4);”+ “Slices=(12.3, blue, ‘Marketing’, cyan), (4.6, antiquewhite, ‘Sales’), (40.1, aqua, ‘Production’), (18.4, aquamarine, ‘Support’);”); // Above, we set the parameters for the pie chart, // including the data and labels which we generated // in the loop above ( SliceData ), and the Legend, // label position, header, and other properties. // Again, have a look at the NetCharts documentation // for all of the possible parameters. pie.loadParams (”Update”); // Tell the pie chart class we’ve sent it new // parameters to display.
We offer quality web hosting with only $3.99 per month with unlimited email addresses, unlimited bandwidth, and unlimited server space. Check our web hosting unlimited bandwidth section.