From: Nathan W. <wo...@vi...> - 2005-10-31 16:44:28
|
Thanks Anjo, that's exactly what I needed. On Oct 31, 2005, at 6:11 AM, Anjo Krank wrote: > The stuff below is from a mail I sent last year. > > Cheers, Anjo > > Am 31.10.2005 um 04:25 schrieb Nathan Walker: > > >> Can someone please point me to the current wonder docs for ERPlot =20 >> framework or is there any good documentation on how to use the =20 >> ERPlot framework. I'd like try using all the components but I =20 >> might could get a heads up on how to use all of them if someone =20 >> could easily explain how to properly implement ERPBarChart. What =20 >> bindings are necessary and what exactly they need to be bound =20 >> to ?? I am confused on exactly how to use this. Maybe a simple =20 >> 1-2-3 guide to bind up a chart ?? >> >> Thanks for anything, you guys are the best! >> -- >> Nathan >> > > Von: kr...@lo... > Betreff: [Wonder-disc] ERPlot enhancements > Datum: 22. Dezember 2004 11:47:58 MEZ > An: won...@li... > > All, > > just a quick heads up that I revamped ERPlot a bit - it should now =20 > be actually usable instead of the proof-of-concept it was previously:) > > There was still a bug with the PieChart stuff in the commits from =20 > yesterday, but now you should be able to have sth like this in your =20= > Test.java: > > public NSArray items() { > NSMutableArray items =3D new NSMutableArray(); > NSMutableArray products =3D new NSMutableArray(); > NSMutableArray invoices =3D new NSMutableArray(); > Random random =3D new Random(); > for(int i =3D 0; i < 10; i++) { > products.addObject=20 > (ERXDictionaryUtilities.dictionaryWithObjectsAndKeys(new Object[] { > "PID-" +(random.nextInt(1000)+10), "ID" > })); > } > for(int i =3D 0; i < 10; i++) { > invoices.addObject=20 > (ERXDictionaryUtilities.dictionaryWithObjectsAndKeys(new Object[] { > ERXTimestampUtilities.unixDate(new Integer((new =20= > Random()).nextInt(1000)+10)), "date", > "IID-" +(random.nextInt(1000)+10), "ID" > })); > int prods =3D random.nextInt(5)+5; > for(int j =3D 0; j < prods; j++ ) { > Object item =3D =20 > ERXDictionaryUtilities.dictionaryWithObjectsAndKeys(new Object[] { > invoices.lastObject(), "invoice", > products.objectAtIndex(j), "product", > new Integer(random.nextInt(1000)+10), "amount" > }); > items.addObject(item); > } > } > return items; > } > > > This is just a dummy that fakes a list of invoice lime items which =20 > you would normally get from your DB or wherever. The items have =20 > relations to "product" and "invoice". Then setting up a few more =20 > properties: > > public NSDictionary configuration() { > return ERXDictionaryUtilities.dictionaryWithObjectsAndKeys=20 > (new Object[] { > CategoryLabelPositions.UP_45, =20 > "categoryPlot.domainAxis.categoryLabelPositions" > }); > } > > will display the invoice numbers with a 45 degree angle, making =20 > them a bit more readable:) > > No, when you bind that like: > > Test.wo/Test.html: > > <webobject name=3DPieChart></webobject> > <webobject name=3DCategoryChart></webobject> > > Test.wo/Test.wod: > > PieChart: ERPPieChart { > items =3D items; > nameKey =3D "product.ID"; > valueKey =3D "amount"; > name =3D "Share of products"; > chartType =3D "PieChart"; > } > > CategoryChart: ERPCategoryChart { > items =3D items; > nameKey =3D "product.ID"; > categoryKey =3D "invoice.ID"; > valueKey =3D "amount"; > name =3D "prod"; > chartType =3D "StackedAreaChart"; > configuration =3D configuration; > } > > you will get this: > > > > > <Bild 2.pdf> > > > Viola! Instant charts - and even with a rollover (that=B4s the label =20= > in the right chart). > > We'll see if I can win the WWDC contest for best component this =20 > year:) But there's more, as you can supply a dataset instead of =20 > letting ERP handle the item creation, I was able to make charts of =20 > *all* our DynaReporting reports with absolutely no work on my part. =20= > The trick was to split up the attributes into separate charts, then =20= > I had two methods for constructing the dataset, one with =20 > attributes, one without and I was done (for *all* the 30+ reports =20 > we had!). > > Cheers, Anjo > > PS: The snippet below should show how you can generate your own =20 > datasets from a DRModel. The code should live in a subclass of =20 > WRReport. It will not be able to stand alone and is heavyly =20 > dependent on the ordering in my reports (day as the left-most =20 > column, group-able by day, week, month and year), but should give =20 > you an idea how to extract the data. > > public Dataset datasetForAttribute() { > DefaultCategoryDataset dataset =3D new = DefaultCategoryDataset(); > > Integer attribTotalKey =3D new Integer(model=20 > ().flatAttributeList().indexOfObject(attrib)); > > DRGroup dayGroup =3D (DRGroup) model().vList().objectAtIndex=20= > (0); > DRSubMasterCriteria daySubMasterCriteria =3D =20 > (DRSubMasterCriteria) dayGroup.masterCriteria().subCriteriaList=20 > ().objectAtIndex(0); > String dayKey =3D daySubMasterCriteria.keyDesc(); > NSArray dayCriterias =3D dayGroup.sortedCriteriaList(); > Format dayFormat =3D DRCriteria.formatterForFormat=20 > (daySubMasterCriteria.format()); > > NSMutableDictionary coordinates =3D new NSMutableDictionary(); > for(Enumeration en =3D model().hList().objectEnumerator(); =20 > en.hasMoreElements();) { > > DRGroup mainGroup =3D (DRGroup)en.nextElement(); > DRSubMasterCriteria mainSubMasterCriteria =3D =20 > (DRSubMasterCriteria) mainGroup.masterCriteria().subCriteriaList=20 > ().objectAtIndex(0); > String mainKey =3D mainSubMasterCriteria.keyDesc(); > NSArray mainCriterias =3D mainGroup.sortedCriteriaList(); > > for (Enumeration values =3D mainCriterias.objectEnumerator=20= > (); values.hasMoreElements();) { > DRCriteria mainCriteria =3D (DRCriteria)=20 > values.nextElement(); > String label =3D (String) mainCriteria.valueDict=20 > ().objectForKey(mainKey); > coordinates.setObjectForKey(mainCriteria, =20 > mainGroup.masterCriteria().keyDesc()); > if(!mainCriteria.isTotal()) { > for (Enumeration days =3D =20 > dayCriterias.objectEnumerator(); days.hasMoreElements();) { > DRCriteria dayCriteria =3D (DRCriteria)=20 > days.nextElement(); > Object o =3D dayCriteria.valueDict=20 > ().objectForKey(dayKey); > NSTimestamp ts =3D null; > if(o instanceof Day) { > ts =3D new NSTimestamp(((Day)=20 > o).getTimestamp()); > } else if(o instanceof NSTimestamp) { > ts =3D (NSTimestamp)o; > } > if(ts !=3D null && !dayCriteria.isTotal()) { > double value =3D 0.0D; > String dayLabel =3D dayFormat.format(ts); > coordinates.setObjectForKey=20 > (dayCriteria, dayGroup.masterCriteria().keyDesc()); > DRRecordGroup recordGroup =3D model=20 > ().recordGroupForCoordinates(coordinates); > String keyPath =3D attrib.keyPath(); > if(keyPath.startsWith("~")) { > value =3D DRValueConverter.converter=20= > ().doubleForValue(WOOgnl.factory().getValue(keyPath.substring(1), =20 > recordGroup.rawRecordList())); > } else { > DRValue drValue =3D (DRValue) =20 > recordGroup.totals().objectForKey(attribTotalKey); > if(drValue !=3D null) { > value =3D drValue.total(); > } > } > dataset.setValue(value, label, dayLabel); > } > } > } > } > } > return dataset; > } > > > public Dataset dataset() { > DefaultCategoryDataset dataset =3D new = DefaultCategoryDataset(); > > DRGroup dayGroup =3D (DRGroup) model().vList().objectAtIndex=20= > (0); > DRSubMasterCriteria daySubMasterCriteria =3D =20 > (DRSubMasterCriteria) dayGroup.masterCriteria().subCriteriaList=20 > ().objectAtIndex(0); > String dayKey =3D daySubMasterCriteria.keyDesc(); > NSArray dayCriterias =3D dayGroup.sortedCriteriaList(); > Format dayFormat =3D DRCriteria.formatterForFormat=20 > (daySubMasterCriteria.format()); > > NSMutableDictionary coordinates =3D new NSMutableDictionary(); > for(Enumeration en =3D model().hList().objectEnumerator(); =20 > en.hasMoreElements();) { > > DRGroup mainGroup =3D (DRGroup)en.nextElement(); > DRSubMasterCriteria mainSubMasterCriteria =3D =20 > (DRSubMasterCriteria) mainGroup.masterCriteria().subCriteriaList=20 > ().objectAtIndex(0); > String mainKey =3D mainSubMasterCriteria.keyDesc(); > NSArray mainCriterias =3D mainGroup.sortedCriteriaList(); > > for (Enumeration values =3D mainCriterias.objectEnumerator=20= > (); values.hasMoreElements();) { > DRCriteria mainCriteria =3D (DRCriteria)=20 > values.nextElement(); > String label =3D (String) mainCriteria.valueDict=20 > ().objectForKey(mainKey); > coordinates.setObjectForKey(mainCriteria, =20 > mainGroup.masterCriteria().keyDesc()); > if(!mainCriteria.isTotal()) { > for (Enumeration days =3D =20 > dayCriterias.objectEnumerator(); days.hasMoreElements();) { > DRCriteria dayCriteria =3D (DRCriteria)=20 > days.nextElement(); > Object o =3D dayCriteria.valueDict=20 > ().objectForKey(dayKey); > if(o instanceof Day) { > Day day =3D (Day)o; > if(!dayCriteria.isTotal()) { > String dayLabel =3D dayFormat.format=20= > (new NSTimestamp(day.getTimestamp())); > coordinates.setObjectForKey=20 > (dayCriteria, dayGroup.masterCriteria().keyDesc()); > DRRecordGroup recordGroup =3D model=20 > ().recordGroupForCoordinates(coordinates); > Number value =3D (Number) =20 > recordGroup.rawRecordList().valueForKeyPath(recordGroupTotalToShow()); > dataset.setValue(value, label, =20 > dayLabel); > } > } > } > } > } > } > return dataset; > } > > > |