相关:How can I share DomainAxis/RangeAxis across subplots without drawing them on each plot?
注意 - 我最初把它写成一个问题,然后意识到我的错误,所以我决定分享这些知识,因为我已经把这一切都输出了。
在JFreeChart中,有两种绘图类型共享一个轴范围并只绘制一个轴,同时与它们的子图共享该信息。这些是CombinedDomainXYPlot
和CombinedRangeXYPlot
。我将重点关注CombinedDomainXyPlot
,但另一个应该与此问题的目的相同。看看绘制代码,我们看到:
...
setFixedRangeAxisSpaceForSubplots(null);
AxisSpace space = calculateAxisSpace(g2, area);
Rectangle2D dataArea = space.shrink(area, null);
// set the width and height of non-shared axis of all sub-plots
setFixedRangeAxisSpaceForSubplots(space);
// draw the shared axis
ValueAxis axis = getDomainAxis();
RectangleEdge edge = getDomainAxisEdge();
double cursor = RectangleEdge.coordinate(dataArea, edge);
AxisState axisState = axis.draw(g2, cursor, area, dataArea, edge, info); // <- draw the share axis
if (parentState == null) {
parentState = new PlotState();
}
parentState.getSharedAxisStates().put(axis, axisState); // <- put the state of the shared axis in a shared object
// draw all the subplots
for (int i = 0; i < this.subplots.size(); i++) {
XYPlot plot = (XYPlot) this.subplots.get(i);
PlotRenderingInfo subplotInfo = null;
if (info != null) {
subplotInfo = new PlotRenderingInfo(info.getOwner());
info.addSubplotInfo(subplotInfo);
}
plot.draw(g2, this.subplotAreas[i], anchor, parentState, subplotInfo); // <- pass this shared object to the subplot draw function.
}
...
在子图(XYPlot)绘制方法中,我们看到:
domainAxisState = (AxisState) parentState.getSharedAxisStates().get(getDomainAxis());
getDomainAxis()
方法是调用getDomainAxis(0)
,即:
public ValueAxis getDomainAxis(int index) {
ValueAxis result = null;
if (index < this.domainAxes.size()) {
result = (ValueAxis) this.domainAxes.get(index); //<- try to find this domain axis in self
}
if (result == null) { //<- if not found in self ...
Plot parent = getParent();
if (parent instanceof XYPlot) {
XYPlot xy = (XYPlot) parent;
result = xy.getDomainAxis(index); //<- ...try to get from parent
}
}
return result;
}
此处parent
是CombinedDomainXYPlot
。这将从CombinedDomainXYPlot
返回对domainAxis的引用,用于从axisState
对象检索parentState
。似乎getDomainAxis()
方法不用于获取绘制轴,仅用于获取对其它目的的引用。
我正在研究这个因为我试图使用相同的技术将多个共享轴传递给多个不同的绘图组,但只绘制一次。这种技术似乎有效,但现在有一些小故障,即缩放图表,只获取状态信息不会更新具有轴的主图...工作,但希望这些信息对于线下的人有用
谢谢,
伊戈尔
答案 0 :(得分:0)
回答问题帖子。
如上所述,Sub Coa()
Coa.Unprotect Password:=Password
'
' Coa Macro
' create coa
'
' Keyboard Shortcut: Ctrl+Shift+C
'
Sheets("GeneralFormat").Select
ActiveSheet.Range("$B:$B").AutoFilter Field:=1, Criteria1:=Array("1", "10", _
"15", "20", "25", "5", "30", "35", "40", "45", "50", "55", "60", "65", "70", _
"75", "80", "85", "90", "95", "100"), Operator:=xlFilterValues
Range("D6:O105").Select
Selection.Copy
Sheets("CoA").Select
ActiveSheet.Range("E25:E25").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
Sheets("GeneralFormat").Select
Selection.AutoFilter
Sheets("CoA").Select
Coa.Protect Password:=Password
End Sub
Sub Button2_Click()
Dim sh As Worksheet
Dim yourPassword As String
yourPassword = "Password"
For Each sh In ActiveWorkbook.Worksheets
sh.Unprotect Password:=Password
' ---------------------------------------------------------------------------------------------------------------------------------------
Sheets("GeneralFormat").Select
ActiveSheet.Range("$B:$B").AutoFilter Field:=1, Criteria1:=Array("1", "10", _
"15", "20", "25", "5", "30", "35", "40", "45", "50", "55", "60", "65", "70", _
"75", "80", "85", "90", "95", "100"), Operator:=xlFilterValues
Range("D6:O105").Select
Selection.Copy
Sheets("CoA").Select
ActiveSheet.Range("E25:E25").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
Sheets("GeneralFormat").Select
Selection.AutoFilter
Sheets("CoA").Select
' --------------------------------------------------------------------------------------------------------------------------------------
For Each sh In ActiveWorkbook.Worksheets
sh.Protect Password:=Password
Next sh
End Sub
中的getDomainAxis()
方法显然不用于获取绘制轴,仅用于获取其他目的的引用。因此,如果您覆盖此方法以链接到另一个轴并将其状态信息放入共享对象,则此状态信息将在图之间共享。