Skip to content

Commit 443cbb5

Browse files
committed
1 parent 10ef7df commit 443cbb5

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

Graphing/SetPlotModifier.cpp

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
2+
////////////////////////////////////////////////////////////////////////////////////
3+
//This example is about set plot's modifier
4+
////////////////////////////////////////////////////////////////////////////////////
5+
6+
#include <Origin.h>
7+
8+
//use SetModifier to set plot label
9+
void set_label_by_SetModifier()
10+
{
11+
//prepare data
12+
Worksheet wks;
13+
wks.Create("origin");
14+
if(!wks)
15+
return;
16+
wks.AddCol();
17+
18+
vector vn = {1,2,3,4,5};
19+
for(int ii = 0; ii < 3; ii++)
20+
{
21+
Dataset ds(wks, ii);
22+
ds = vn;
23+
}
24+
25+
//plot
26+
DataRange dr;
27+
dr.Add(wks, 0, "X");
28+
dr.Add(wks, 1, "Y");
29+
30+
GraphPage gp;
31+
gp.Create("Origin");
32+
GraphLayer gl = gp.Layers();
33+
gl.AddPlot(dr, IDM_PLOT_SCATTER);
34+
gl.Rescale();
35+
36+
//set label
37+
Column col(wks, 2);
38+
DataPlot dp = gl.DataPlots(0);
39+
if(!dp)
40+
return;
41+
dp.SetModifier(COLDESIG_PLOTLABEL_FORM, col);//see PlotDesignationEx for more modifier types.
42+
43+
vector<int> vnDesigs;
44+
vector<string> saNames;
45+
dp.GetModifiers(vnDesigs, saNames);
46+
47+
vector<uint> vecIndex;
48+
if(vnDesigs.Find(vecIndex, COLDESIG_PLOTLABEL_FORM) > 0)
49+
{
50+
printf("label form = %s\n", saNames[ vecIndex[0] ]);
51+
}
52+
}
53+
54+
//use ApplyFormat to set plot label
55+
void set_label_by_applyformat()
56+
{
57+
//prepare data
58+
Worksheet wks;
59+
wks.Create("origin");
60+
if(!wks)
61+
return;
62+
wks.AddCol();
63+
64+
vector vn = {1,2,3,4,5};
65+
for(int ii = 0; ii < 3; ii++)
66+
{
67+
Dataset ds(wks, ii);
68+
ds = vn;
69+
}
70+
71+
//plot
72+
DataRange dr;
73+
dr.Add(wks, 0, "X");
74+
dr.Add(wks, 1, "Y");
75+
76+
GraphPage gp;
77+
gp.Create("Origin");
78+
GraphLayer gl = gp.Layers();
79+
gl.AddPlot(dr, IDM_PLOT_SCATTER);
80+
gl.Rescale();
81+
82+
//set label
83+
DataPlot dp = gl.DataPlots(0);
84+
if(dp)
85+
{
86+
Tree trFmt;
87+
TreeNode trEnable = trFmt.Root.Label.AddNode("Enable");
88+
trEnable.nVal = 1;
89+
90+
OQCOLOR nLab;
91+
int ycol = 1, labelcol = 2;
92+
//convert the offset(modifier column to y column) to theme internal value
93+
okutil_get_ocolor_by_col(&nLab, labelcol, ycol, SYMB_COLOR_COLTYPE_INDEX);
94+
95+
trFmt.Root.Label.Form.nVal = nLab;
96+
if ( 0 == dp.UpdateThemeIDs(trFmt.Root) )
97+
dp.ApplyFormat(trFmt, true, true);
98+
}
99+
}

0 commit comments

Comments
 (0)