⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chartcomponent.java

📁 OLAP 的客户端代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                        //number = formatter.parse(value, new ParsePosition(0));
		}
		catch (Exception e) {
			number = null;
		}
		return number;
	}
        /**
	 * Get a unique name string for a dataitem derived from the member chain
	 *
	 * @param myTree  (full member tree)
         * @param members - the list to be processed (either X/Y axis)
	 * @return retValue as String
	 */
        private String buildName( MemberTree myTree, Member [] members){
            String retValue = new String();
            HashMap levelMap = new HashMap();
            HashMap hierarchyMap = new HashMap();
            for (int j=members.length-1;j>=0;j--){
                Member member = members[j];
                while (member!=null){
                    // only process if no other items from this level processed - should not be duplicates!
                    if (!levelMap.containsValue(member.getLevel())){
                        levelMap.put(member.getLevel().toString(),member.getLevel());
                        if (member.getRootDistance()==0){
                            // if root member, only add to name if no other members of the hierarchy are already added
                            if (!hierarchyMap.containsValue(member.getLevel().getHierarchy())
                            || myTree.getRootMembers(member.getLevel().getHierarchy()).length>1){
                                hierarchyMap.put(member.getLevel().getHierarchy().toString(),member.getLevel().getHierarchy());
                                retValue=member.getLabel()+"."+retValue;
                            }
                        } else{
                            hierarchyMap.put(member.getLevel().getHierarchy().toString(),member.getLevel().getHierarchy());
                            retValue=member.getLabel()+"."+retValue;
                        }
                    }
                    member = myTree.getParent(member);
                }
            }
            return retValue;
        }
	/**
	 * Build a jfreechart CategoryDataset with multiple series
	 *
	 */
        private DefaultCategoryDataset build2dimDataset() {

            DefaultCategoryDataset dataset = new DefaultCategoryDataset();

            // column axis

            List columnPositions = result.getAxes()[0].getPositions();//ladX.getPositions();
            int colCount = columnPositions.size();

            // row axis

            List rowPositions = result.getAxes()[1].getPositions();//ladY.getPositions();
            int rowCount = rowPositions.size();
            List cells = result.getCells();

            // get the full member tree
            MemberTree myTree = ((MemberTree) olapModel.getExtension(MemberTree.ID));

            // for each column, starting with the bottom member, progress up the mmeber chain until the root is reached
            // keep track of the levels and hierarchies to avoid duplicates on level or hierarchys.
            //      *note: keeping track of the levels might be just extra work, I don't know if they CAN be repeated.
            //          if not, that logic can be easily removed (see buildName - above)
            // For each hierarchy, If a root member is reached (getRootDistance()=0), then only include it if there have been no other
            // lower level members already added:
            //       ie. All_dim1.dim1_lvl1.dim1_lvl2.All_dim2.dim2_lvl1 renders as dim1_lvl1.dim1_lvl2.dim2_lvl1
            //          whereas All_dim1.All_dim2 renders as the same.
            // The important part is that we include each parent on the way up, to ensure a unique name to
            // place in the map for the dataset (no longer overwriting each other)


            for(int i=0;i<colCount;i++){
                Position p= (Position) columnPositions.get(i);
                Member colMembers[] =p.getMembers();

                // build the label name for this column
                String label=buildName(myTree, colMembers);

                // For each row, use the same logic to build a unique key for each data item
                for(int k=0;k<rowCount;k++){
                    Position rp= (Position) rowPositions.get(k);
                    Member rowMembers[] =rp.getMembers();

                    // build key name
                    String key=buildName(myTree, rowMembers);

                    Cell cell = (Cell) cells.get((k * colCount) + i);
                    dataset.addValue(getNumberValue(cell), label.toString(), key.toString());
                }

            }
            return dataset;
        }

	/**
	 * @return
	 */
	public int getColCount() {
		return colCount;
	}

	/**
	 * true means that render() will create a new chart
	 */
	public boolean isDirty() {
	  return dirty;
	}

	public void setDirty(boolean dirty) {
	  this.dirty = dirty;
	}

	public void modelChanged(ModelChangeEvent e) {
	  this.dirty = true;
	}

	public void structureChanged(ModelChangeEvent e) {
	  this.dirty = true;
	}

	/**
	 * @return
	 */
	public int getChartHeight() {
		return chartHeight;
	}

	/**
	 * @param chartHeight
	 */
	public void setChartHeight(int chartHeight) {
		this.chartHeight = chartHeight;
		this.dirty = true;
	}

	/**
	 * @return
	 */
	public String getChartTitle() {
		return chartTitle;
	}

	/**
	 * @param chartTitle
	 */
	public void setChartTitle(String chartTitle) {
		this.chartTitle = chartTitle;
		this.dirty = true;
	}

	/**
	 * @return
	 */
	public int getChartType() {
		return chartType;
	}

	/**
	 * @param chartType
	 */
	public void setChartType(int chartType) {
		this.chartType = chartType;
		this.dirty = true;
	}

	/**
	 * @return
	 */
	public int getChartWidth() {
		return chartWidth;
	}

	/**
	 * @param chartWidth
	 */
	public void setChartWidth(int chartWidth) {
		this.chartWidth = chartWidth;
		this.dirty = true;
	}

	/**
	 * @return
	 */
	public String getHorizAxisLabel() {
		return horizAxisLabel;
	}

	/**
	 * @param axisLabel
	 */
	public void setHorizAxisLabel(String axisLabel) {
		horizAxisLabel = axisLabel;
		this.dirty = true;
	}

	/**
	 * @return
	 */
	public boolean getShowLegend() {
		return showLegend;
	}

	/**
	 * @param showLegend
	 */
	public void setShowLegend(boolean showLegend) {
		this.showLegend = showLegend;
		this.dirty = true;
	}

	/**
	 * @return
	 */
	public String getFontName() {
		return fontName;
	}

	/**
	 * @param titleFont
	 */
	public void setFontName(String fontname) {
		this.fontName = fontname;
		this.dirty = true;
	}

	/**
	 * @return
	 */
	public String getVertAxisLabel() {
		return vertAxisLabel;
	}

	/**
	 * @param axisLabel
	 */
	public void setVertAxisLabel(String axisLabel) {
		vertAxisLabel = axisLabel;
		this.dirty = true;
	}

	/**
	 * @return
	 */
	public int getFontSize() {
		return fontSize;
	}

	/**
	 * @param fontSize
	 */
	public void setFontSize(int fontSize) {
		this.fontSize = fontSize;
		this.dirty = true;
	}

	/**
	 * @return
	 */
	public int getFontStyle() {
		return fontStyle;
	}

	/**
	 * @param fontStyle
	 */
	public void setFontStyle(int fontStyle) {
		this.fontStyle = fontStyle;
		this.dirty = true;
	}

	/**
	 * @return
	 */
	public int getBgColorB() {
		return bgColorB;
	}

	/**
	 * @param bgColorB
	 */
	public void setBgColorB(int bgColorB) {
		this.bgColorB = checkRGB(bgColorB);
		this.dirty = true;
	}

	/**
	 * @return
	 */
	public int getBgColorG() {
		return bgColorG;
	}

	/**
	 * @param bgColorG
	 */
	public void setBgColorG(int bgColorG) {
		this.bgColorG = checkRGB(bgColorG);
		this.dirty = true;
	}

	/**
	 * @return
	 */
	public int getBgColorR() {
		return bgColorR;
	}

	/**
	 * @param bgColorR
	 */
	public void setBgColorR(int bgColorR) {
		this.bgColorR = checkRGB(bgColorR);
		this.dirty = true;
	}

	/**
	 * Enforce limits of 0 - 255 for RGB values.
	 */
	private int checkRGB(int v) {
		if ( v > 255 ) {
			v = 255;
		}
		else if ( v < 0 ) {
			v = 0;
		}
		return v;
	}
        /**
	 * A URLGenerator class to generate pie urls that work with jpivot
	 * @author ati
	 *
	 */
	public class jpivotPieURLGenerator extends StandardPieURLGenerator {
            /** Prefix to the URL */
		private String prefix = "";

                private List cells = result.getCells();

                private int rowCount;

                private TableOrder order;  // COLUMN or ROW  - used to calculate cell Position

                jpivotPieURLGenerator() {
		}

		jpivotPieURLGenerator(String prefix) {
			this.prefix = prefix;
		}
                /*
                 * Use this constructor to set dataExtraction type (PER_COLUMN/PER_ROW), and allow for
                 * rowcount of current dataset  (could be changed to just take rowCount)
                 */
                jpivotPieURLGenerator(TableOrder order, DefaultCategoryDataset dataset){
                        this.order= order;
                        this.rowCount=dataset.getRowCount();
                }

                /*
                 * As above with web controller URL
                 */
                jpivotPieURLGenerator(TableOrder order, DefaultCategoryDataset dataset, String controllerURL){
                    this(order, dataset);
                    this.prefix = controllerURL;
                }
		/**
		 * Implementation of generateURL that integrates with jpivot/wcf framework.
		 * A request handler is added for each cell/item.
		 * No test is done to see if a cell is drillable, since the url has to added (I think, like an all or nothing ?)
		 * Generates a URL for a particular item within a series.
		 *
		 * @param data  the dataset.
		 * @param key  the data item key.
		 * @param pieIndex the index of the pie containing key (zero-based).
		 *
		 * @return the generated URL
		 */
		public String generateURL(PieDataset data, Comparable key, int pieIndex) {
			String url = prefix;
                        int index = data.getIndex(key);

                        int cellpos;
                        if (order == TableOrder.BY_COLUMN){
                            cellpos = (pieIndex*rowCount)+index;
                        } else {
                            cellpos = pieIndex+(rowCount*index);
                        }

			if ( canDrillThrough((Cell) cells.get(cellpos)) && (!((Cell) cells.get(cellpos)).isNull()) ) {
				String id = DomUtils.randomId();
				dispatcher.addRequestListener(
					id,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -