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

📄 charting.js

📁 在流览器上仿CS界面的JAVASCRIPT脚本
💻 JS
📖 第 1 页 / 共 3 页
字号:
sb.push("m "+x0+","+y2+" l "+x1+","+y2);else sb.push("m "+y2+","+x0+" l "+y2+","+x1);y+=minor;}
this._minorValue.setHtmlProperty("path",sb.join("")+"e");}};_p._updateMajorCategory=function(){if(this.getShowMajorCategory()){var y0=Math.round(this._graph._valueAxis.getMinimum()*this._graph._scaleFactor);var y1=Math.round(this._graph._valueAxis.getMaximum()*this._graph._scaleFactor);var major=this._graph._categoryAxis.getMajorTickInterval();var catMax=this._graph._categoryAxis.getMaximum();var sb=[];var x=major;var onX=this._graph._getCategoryOnXAxis();var x2;while(x<catMax){x2=Math.round(x*this._graph._catScaleFactor);if(onX)
sb.push("m "+x2+","+y0+" l "+x2+","+y1);else sb.push("m "+y0+","+x2+" l "+y1+","+x2);x+=major;}
this._majorCategory.setHtmlProperty("path",sb.join("")+"e");}};_p._updateMinorCategory=function(){if(this.getShowMinorCategory()){var y0=Math.round(this._graph._valueAxis.getMinimum()*this._graph._scaleFactor);var y1=Math.round(this._graph._valueAxis.getMaximum()*this._graph._scaleFactor);var minor=this._graph._categoryAxis.getMinorTickInterval();var catMax=this._graph._categoryAxis.getMaximum();var sb=[];var x=minor;var onX=this._graph._getCategoryOnXAxis();var x2;while(x<catMax){x2=Math.round(x*this._graph._catScaleFactor);if(onX)
sb.push("m "+x2+","+y0+" l "+x2+","+y1);else sb.push("m "+y0+","+x2+" l "+y1+","+x2);x+=minor;}
this._minorCategory.setHtmlProperty("path",sb.join("")+"e");}};_p.setVisible=function(b){this._desiredVisible=b;BiComponent.prototype.setVisible.call(this,b&&this._graph._getSupportsGridLines());};_p.getVisible=function(){return this._desiredVisible;};_p._updateVisible=function(){this.setVisible(this._desiredVisible);};function BiAbstractChart(oGraph,oSeries)
{if(!oGraph)
return;BiAbstractChartBase.call(this,oGraph,oSeries);this.setStyleProperty("width","100%");this.setStyleProperty("height","100%");this.setZIndex(2);};var _p=BiAbstractChart.prototype=new BiAbstractChartBase;_p._className="BiAbstractChart";function BiAbstractChartSection(oChart,oCategory)
{if(!oChart)
return;BiAbstractChartSectionBase.call(this,oChart,oCategory);this.setHtmlProperty("fillcolor",this.getFillColor());this.setHtmlProperty("strokecolor",this.getStrokeColor());this._createFillEl();this._createStrokeEl();};var _p=BiAbstractChartSection.prototype=new BiAbstractChartSectionBase;_p._className="BiAbstractChartSection";BiGraph._addExtendedFillInterface(_p);BiGraph._addExtendedStrokeInterface(_p);_p.getStrokeOpacity=function(){return this._graph.getPresentationManager().getStrokeOpacity(this._seriesId,this._categoryId);};_p.getFillOpacity=function(){return this._graph.getPresentationManager().getFillOpacity(this._seriesId,this._categoryId);};_p.getFillColor2=function(){return this._graph.getPresentationManager().getFillColor2(this._seriesId,this._categoryId);};_p.getFillType=function(){return this._graph.getPresentationManager().getFillType(this._seriesId,this._categoryId);};_p.getFillAngle=function(){return this._graph.getPresentationManager().getFillAngle(this._seriesId,this._categoryId);};_p.setStrokeOpacity=function(n){this._strokeEl.setHtmlProperty("opacity",n);};_p.setStrokeColor=function(s){this.setHtmlProperty("strokecolor",s);};_p.setFillOpacity=function(n){this._fillEl.setHtmlProperty("opacity",n);};_p.setFillColor=function(s){this.setHtmlProperty("fillcolor",s);};_p.setFillColor2=function(s){this._fillEl.setHtmlProperty("color2",s);};_p.setFillType=function(s){this._fillEl.setHtmlProperty("type",s);};_p.setFillAngle=function(s){this._fillEl.setHtmlProperty("angle",s);};function BiLineChart(oGraph,oSeries){BiAbstractChart.call(this,oGraph,oSeries);this._pathComponent=new BiComponent;this._pathComponent._tagName="v:shape";this._pathComponent.setHtmlProperty("strokecolor",this.getStrokeColor());this._pathComponent.setHtmlProperty("strokeweight","1");this._pathComponent.setHtmlProperty("filled","false");this.add(this._pathComponent);this._markersByCat={};this._createShapeType();this._createStrokeEl(this._pathComponent);this.setStrokeOpacity(this.getStrokeOpacity());this.add(this._lineMarker);};var _p=BiLineChart.prototype=new BiAbstractChart;_p._className="BiLineChart";_p._tagName="v:group";_p._showMarkers=true;BiGraph._addExtendedStrokeInterface(_p);_p.getStrokeOpacity=function(){return this._graph.getPresentationManager().getStrokeOpacity(this._seriesId,null);};_p._setPath=function(){var sb=[];var dx=this._graph._categoryAxis.getAxisBetweenCategories()?0.5:0;var vs=this._series.getValues();var l=vs.length;for(var i=0;i<l;i++){if(vs[i-1]!=null&&vs[i]!=null)
sb.push("m"+((i-1+dx)*this._graph._catScaleFactor)+","+Math.round(vs[i-1]*this._graph._scaleFactor)+"l"+((i+dx)*this._graph._catScaleFactor)+","+Math.round(vs[i]*this._graph._scaleFactor));}
sb.push("e");this._pathComponent.setHtmlProperty("path",sb.join(""));};_p.getComponentByCategoryId=function(sCatId){return this._markersByCat[sCatId];};_p._createMarkers=function(){var cs=this.getChildren();var tmp;for(var i=cs.length-1;i>=2;i--){tmp=cs[i];this.remove(tmp);tmp.dispose();}
this._markersByCat={};if(this._showMarkers){var dx=this._graph._categoryAxis.getAxisBetweenCategories()?0.5:0;var pm=this._graph.getPresentationManager();var sId=this._series.getId();var vs=this._series.getValues();var cats=this._graph.getCategories();var l=vs.length;var m,cId;for(var i=0;i<l;i++){cId=cats[i].getId();if(vs[i]!=null&&pm.getMarkerVisible(sId,cId)){m=new BiLineMarker(this,cats[i]);m.setSize(this._coordSizeW/50,this._coordSizeH/50);m.setLocation((i+dx)*this._graph._catScaleFactor,Math.round(vs[i]*this._graph._scaleFactor));this.add(m);this._markersByCat[cats[i].getId()]=m;}}}};_p._updateMarkerByCategoryId=function(sId){var m=this._markersByCat[sId];if(m)
m.setTop(this._series.getValueByCategoryId(sId)*this._graph._scaleFactor);};_p._updateCoordSize=function(sCoordSize,sCoordOrigin){var p=sCoordSize.split(",");var w=Number(p[0]),h=Number(p[1]);p=sCoordOrigin.split(",");var x=Number(p[0]),y=Number(p[1]);this.setHtmlProperty("coordsize",sCoordSize);this.setHtmlProperty("coordorigin",sCoordOrigin);this._pathComponent.setLocation(x,y);this._pathComponent.setSize(w,h);this._pathComponent.setHtmlProperty("coordsize",sCoordSize);this._pathComponent.setHtmlProperty("coordorigin",sCoordOrigin);this._coordSizeW=w;this._coordSizeH=h;this._createMarkers();};_p.update=function(){this._updateChart();};_p._updateChart=function(){this._setPath();};_p._updateValues=function(){this._setPath();var cats=this._graph.getCategories();for(var i=0;i<cats.length;i++){this._updateValueByCategoryId(cats[i].getId());}};_p._updateValueByCategoryId=function(sId){this._setPath();this._updateMarkerByCategoryId(sId);};_p._createShapeType=function(){var c=new BiComponent;c._tagName="v:shapetype";c.setHtmlProperty("stroked",true);c.setHtmlProperty("filled",true);this._lineMarkerId=c.getHtmlProperty("id");switch(this.getMarkerType()){case"square":c.setHtmlProperty("coordsize","1000,1000");c.setHtmlProperty("path","m -400,-400 l 400,-400 400,400 -400,400 xe");break;case"circle":c.setHtmlProperty("coordsize","1000,1000");c.setHtmlProperty("path","at -500,-500 500,500 0,-500 0,-500 xe");break;case"triangle":c.setHtmlProperty("coordsize","1000,1000");c.setHtmlProperty("path","m -500,-289 l 0,577 500,-289 xe");break;case"diamond":default:c.setHtmlProperty("coordsize","1000,1000");c.setHtmlProperty("path","m -520,0 l 0,-520 520,0 0,520 xe");break;};this._lineMarker=c;};_p.dispose=function(){if(this._disposed)return;BiAbstractChart.prototype.dispose.call(this);this._pathComponent=null;for(var hc in this._markersByCat)
delete this._markersByCat[hc];this._markersByCat=null;};function BiLineMarker(oChart,oCategory){BiAbstractChartSection.call(this,oChart,oCategory);BiGraph._vmlComponent1000(this);this.setHtmlProperty("type","#"+oChart._lineMarkerId);};var _p=BiLineMarker.prototype=new BiAbstractChartSection;_p._className="BiLineMarker";_p._tagName="v:shape";function BiColumnChart(oGraph,oSeries){if(!oGraph)return;BiAbstractChart.call(this,oGraph,oSeries);this._rectsByCat={};BiGraph._vmlComponent1000(this);this.setStyleProperty("width","1000px");this.setStyleProperty("height","1000px");this.setStyleProperty("antialias","false");};var _p=BiColumnChart.prototype=new BiAbstractChart;_p._className="BiColumnChart";_p._tagName="v:group";_p._isBar=false;_p._isStacked=false;_p._isPercentage=false;_p._barSpacing=1;_p.getComponentByCategoryId=function(sCatId){return this._rectsByCat[sCatId];};_p._updateCoordSize=function(sCoordSize,sCoordOrigin){this.setHtmlProperty("coordsize",sCoordSize);this.setHtmlProperty("coordorigin",sCoordOrigin);};_p._updateChart=function(){var el=this._element;var pn=el.parentNode;var ns=el.nextSibling;pn.removeChild(el);var cs=this.getChildren();for(var i=cs.length-1;i>=0;i--)
this.remove(cs[i]);var charts=this._graph.getCharts();var chartCount=charts.length;var index=charts.indexOf(this);var bs=this.getBarSpacing();var w=this._isStacked?1/(1+bs):1/(chartCount+bs);var dx=bs*w/2+(this._isStacked?0:index*w)-(this._graph._categoryAxis.getAxisBetweenCategories()?0:0.5);var vs=this._series.getValues();var l=vs.length;var cats=this._graph.getCategories();var id;for(var i=0;i<l;i++){if(vs[i]!=null){id=cats[i].getId();rect=new BiColumnChartSection(this,cats[i]);if(this._isBar){rect.setLocation(this._graph._scaleFactor*this._getRectTop(id),this._graph._catScaleFactor*(i+dx));rect.setSize(this._graph._scaleFactor*this._getRectHeight(id),this._graph._catScaleFactor*w);}
else{rect.setLocation(this._graph._catScaleFactor*(i+dx),this._graph._scaleFactor*this._getRectTop(id));rect.setSize(this._graph._catScaleFactor*w,this._graph._scaleFactor*this._getRectHeight(id));}
this.add(rect);this._rectsByCat[id]=rect;}}
pn.insertBefore(el,ns);};_p.update=function(){this._updateChart();};_p._updateValues=function(){var cats=this._graph.getCategories();for(var i=0;i<cats.length;i++){this._updateValueByCategoryId(cats[i].getId());}};_p._updateValueByCategoryId=function(sId){this._updateRectByCategoryId(sId);if(this._isStacked){var charts=this._graph.getCharts();var found=this._graph._getPercentageStack();for(var i=0;i<charts.length;i++){if(!found&&charts[i]==this){found=this;continue;}
if(found){charts[i]._updateRectByCategoryId(sId);}}}};_p._updateRectByCategoryId=function(sId){var rect=this._rectsByCat[sId];if(!rect)return;if(this._isBar)
rect.setWidth(this._getRectHeight(sId)*this._graph._scaleFactor);else rect.setHeight(this._getRectHeight(sId)*this._graph._scaleFactor);if(this._isStacked){if(this._isBar)
rect.setLeft(this._getRectTop(sId)*this._graph._scaleFactor);else rect.setTop(this._getRectTop(sId)*this._graph._scaleFactor);}
else{if(this._isBar)
rect.setLeft(0);else rect.setTop(0);}};_p._getRectHeight=function(sCategoryId){return Number(this._series.getValueByCategoryId(sCategoryId));};_p._getRectTop=function(sCategoryId){return 0;};_p.dispose=function(){if(this._disposed)return;BiAbstractChart.prototype.dispose.call(this);for(var hc in this._rectsByCat)
delete this._rectsByCat[hc];this._rectsByCat=null;};function BiBarChart(oGraph,oSeries){BiColumnChart.call(this,oGraph,oSeries);};var _p=BiBarChart.prototype=new BiColumnChart;_p._className="BiBarChart";_p._isBar=true;function BiStackedColumnChart(oGraph,oSeries){BiColumnChart.call(this,oGraph,oSeries);};var _p=BiStackedColumnChart.prototype=new BiColumnChart;_p._className="BiStackedColumnChart";_p._isBar=false;_p._isStacked=true;_p._getRectHeight=function(sCategoryId){return Math.abs(this._series.getValueByCategoryId(sCategoryId));};_p._getRectTop=function(sCategoryId){var charts=this._graph.getCharts();var sum=0;for(var i=0;i<charts.length;i++){if(charts[i]==this)
return sum;sum+=Math.abs(charts[i]._series.getValueByCategoryId(sCategoryId));}
return sum;};function BiStackedBarChart(oGraph,oSeries){BiStackedColumnChart.call(this,oGraph,oSeries);};var _p=BiStackedBarChart.prototype=new BiStackedColumnChart;_p._className="BiStackedBarChart";_p._isBar=true;function BiPercentageStackedColumnChart(oGraph,oSeries){BiColumnChart.call(this,oGraph,oSeries);};var _p=BiPercentageStackedColumnChart.prototype=new BiColumnChart;_p._className="BiPercentageStackedColumnChart";_p._isBar=false;_p._isStacked=true;_p._isPercentage=true;_p._getRectHeight=function(sCategoryId){var charts=this._graph.getCharts();var sum=0;for(var i=0;i<charts.length;i++){sum+=Math.abs(charts[i]._series.getValueByCategoryId(sCategoryId));}
return Math.abs(this._series.getValueByCategoryId(sCategoryId))/sum;};_p._getRectTop=function(sCategoryId){var charts=this._graph.getCharts();var sum=0;var y;for(var i=0;i<charts.length;i++){if(charts[i]==this)
y=sum;sum+=Math.abs(charts[i]._series.getValueByCategoryId(sCategoryId));}
return y/sum;};function BiPercentageStackedBarChart(oGraph,oSeries){BiPercentageStackedColumnChart.call(this,oGraph,oSeries);};var _p=BiPercentageStackedBarChart.prototype=new BiPercentageStackedColumnChart;_p._className="BiPercentageStackedBarChart";_p._isBar=true;function BiColumnChartSection(oChart,oCategory){BiAbstractChartSection.call(this,oChart,oCategory);}
var _p=BiColumnChartSection.prototype=new BiAbstractChartSection;_p._className="BiColumnChartSection";_p._tagName="v:rect";function BiPieChart(oGraph,oSeries){BiAbstractChart.call(this,oGraph,oSeries);this._sectionsByCategory={};this.setLocation(0,0);this.setStyleProperty("width","1000px");this.setStyleProperty("height","1000px");this.setHtmlProperty("coordsize","1000,1000");this.setHtmlProperty("coordorigin","-500,-500");};var _p=BiPieChart.prototype=new BiAbstractChart;_p._className="BiPieChart";_p._tagName="v:group";BiPieChart.prototype.getSeries=function(){return this._series;};BiPieChart.prototype.getGraph=function(){return this._graph;};_p.getComponentByCategoryId=function(sCatId){return this._sectionsByCategory[sCatId];};_p._updateAspectRatio=function(e){var cw=this._graph._chartArea.getWidth();var ch=this._graph._chartArea.getHeight();var coordSize,coordOrigin;if(cw>ch){coordSize=Math.round(cw/ch*1000)+",1000";coordOrigin= -Math.round(cw/ch*500)+",-500";}
else{coordSize="1000,"+Math.round(ch/cw*1000);coordOrigin="-500,"+ -Math.round(ch/cw*500);}
this.setHtmlProperty("coordsize",coordSize);this.setHtmlProperty("coordorigin",coordOrigin);};_p._updateCoordSize=function(sCoordSize,sCoordOrigin){};_p.update=function(){this._updateChart();};_p._updateChart=function(){this._createChartComponents();this._updateAllSections();};_p._updateValues=function(){this._updateAllSections();};_p._updateValueByCategoryId=function(sId){this._updateAllSections();};_p._createChartComponents=function(){var cs=this.getChildren();for(var i=cs.length-1;i>=0;i--){tmp=cs[i];this.remove(tmp);tmp.dispose();}
var cats=this._graph.getCategories();var l=cats.length;var id,section;for(var i=0;i<l;i++){id=cats[i].getId();if(this._series.getValueByCategoryId(id)!=null){section=this._sectionsByCategory[id]=new BiPieChartSection(this,cats[i]);this.add(section);}}};_p._updateAllSections=function(){var sum=0;var values=this._series.getValues();for(var i=0;i<values.length;i++)
sum+=Math.abs(values[i]);var cats=this._graph.getCategories();var l=cats.length;var v=0;var id,section;for(var i=0;i<l;i++){id=cats[i].getId();section=this._sectionsByCategory[id];if(section){section._startAngle=v;v+=Math.abs(this._series.getValueByCategoryId(id)/sum*2*Math.PI);section._endAngle=v;section._setPath();}}};_p.getSupportsValueAxis=function(){return false;};_p.getSupportsCategoryAxis=function(){return false;};_p.getSupportsGridLines=function(){return false;};function BiPieChartSection(oChart,oCategory,nStartAngle,nEndAngle){BiAbstractChartSection.call(this,oChart,oCategory);if(nStartAngle!=null)this._startAngle=nStartAngle;if(nEndAngle!=null)this._endAngle=nEndAngle;if(nStartAngle!=null&&nEndAngle!=null)
this._setPath();BiGraph._vmlComponent1000(this);};var _p=BiPieChartSection.prototype=new BiAbstractChartSection;_p._className="BiPieChartSection";_p._tagName="v:shape";_p._startAngle=null;_p._endAngle=null;_p._radius=0.95;_p._explode=0.05;BiPieChartSection.prototype.getStartAngle=function(){return this._startAngle;};BiPieChartSection.prototype.getEndAngle=function(){return this._endAngle;};BiPieChartSection.prototype.getRadius=function(){return this._radius;};_p.setStartAngle=function(n){if(this._startAngle!=n){this._startAngle=n;this._setPath();}};_p.setEndAngle=function(n){if(this._endAngle!=n){this._endAngle=n;this._setPath();}};_p.setRadius=function(n){if(this._radius!=n){this._radius=n;this._setPath();}};_p.setExplode=function(n){if(this._explode!=n){this._explode=n;this._setPath();}};_p._setPath=function(){var sPath;if(this._startAngle==this._endAngle){sPath="m0,0e";}
else{var r=this._radius*500;var explode=this.getExplode();var centerAngle=Math.PI/2-this._startAngle-(this._endAngle-this._startAngle)/2;var startAngle=Math.PI/2-this._startAngle;var endAngle=Math.PI/2-this._endAngle;var startX=explode*r*Math.cos(centerAngle);var startY=explode*r*Math.sin(centerAngle);var w=r*2;var h=w;var startRadX=Math.round(startX+Math.cos(startAngle)*r);var startRadY=Math.round(startY+Math.sin(startAngle)*r);var endRadX=Math.round(startX+Math.cos(endAngle)*r);var endRadY=Math.round(startY+Math.sin(endAngle)*r);startX=Math.round(startX);startY=Math.round(startY);var left=Math.round(startX-r);var top=Math.round(startY-r);var right=Math.round(left+w);var bottom=Math.round(top+w);sPath="m"+startX+","+startY+"at"+left+","+top+","+right+","+bottom+","+startRadX+","+startRadY+","+endRadX+","+endRadY+"xe";}
this.setHtmlProperty("path",sPath);};

⌨️ 快捷键说明

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