mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-24 17:41:39 +08:00
modified example a bit
This commit is contained in:
parent
ffb70ace09
commit
4949176229
Binary file not shown.
Before Width: | Height: | Size: 99 KiB After Width: | Height: | Size: 112 KiB |
@ -5,7 +5,7 @@
|
||||
## Line Graph with Different Symbols and Line Styles
|
||||
This project (see `./test/jkqtplotter_simpletest_symbols_and_styles/`) simply creates a JKQtPlotter widget (as a new window) and adds a single line-graph (a sine-wave). Data is initialized from two QVector<double> objects.
|
||||
|
||||
The source code of the main application can be found in [`jkqtplotter_simpletest_symbols_and_styles.cpp`](https://github.com/jkriege2/JKQtPlotter/blob/master/jkqtplotter_simpletest_symbols_and_styles/jkqtplotter_simpletest_symbols_and_styles.cpp). Mainly several graphs are generated in a loop and then different symbol and line styles are applied to the graph (set by `graph->set_symbol()` for the symbol and `graph->set_style()` for the line style). The colors are set automtically from an internal default palette. The main loop looks like this:
|
||||
The source code of the main application can be found in [`jkqtplotter_simpletest_symbols_and_styles.cpp`](https://github.com/jkriege2/JKQtPlotter/blob/master/test/jkqtplotter_simpletest_symbols_and_styles/jkqtplotter_simpletest_symbols_and_styles.cpp). Mainly several graphs are generated in a loop and then different symbol and line styles are applied to the graph (set by `graph->set_symbol()` for the symbol and `graph->set_style()` for the line style). The colors are set automtically from an internal default palette. The main loop looks like this:
|
||||
|
||||
```c++
|
||||
QVector<Qt::PenStyle> pens {Qt::NoPen, Qt::SolidLine, Qt::DashLine, Qt::DotLine, Qt::DashDotLine, Qt::DashDotDotLine };
|
||||
@ -26,7 +26,13 @@ The source code of the main application can be found in [`jkqtplotter_simpletes
|
||||
// set symbol + pen style and color
|
||||
graph->set_symbol(static_cast<JKQTPgraphSymbols>(symbolID));
|
||||
graph->set_style(pens[ipen]);
|
||||
|
||||
// set symbol size
|
||||
graph->set_symbolSize(14);
|
||||
// set width of symbol lines
|
||||
graph->set_symbolWidth(1.5);
|
||||
// set width of graph line
|
||||
graph->set_lineWidth(1);
|
||||
|
||||
// graph title is made from symbol+penstyle
|
||||
graph->set_title(JKQTPgraphSymbols2NameString(static_cast<JKQTPgraphSymbols>(graph->get_symbol()))+QString(", ")+JKQTP_QPenStyle2String(graph->get_style()));
|
||||
|
||||
@ -38,6 +44,7 @@ The source code of the main application can be found in [`jkqtplotter_simpletes
|
||||
}
|
||||
```
|
||||
|
||||
In addition to the symbol type and line style, you can also alter the size of the symbols (`graph->set_symbolSize(14)`), the line-width used to draw them (`graph->set_symbolWidth(1.5)`) and the line width of the graph line (`graph->set_lineWidth(1)`). If you want to switch off the line altogether, use `graph->set_drawLine(false`.
|
||||
|
||||
The result looks like this:
|
||||
|
||||
|
@ -25,7 +25,7 @@ int main(int argc, char* argv[])
|
||||
// 3. now we make several plots with different symbol styles and line-styles
|
||||
// for that we iterate over every symbol style and at the same time over
|
||||
// pen styles from the vector pens
|
||||
QVector<Qt::PenStyle> pens {Qt::NoPen, Qt::SolidLine, Qt::DashLine, Qt::DotLine, Qt::DashDotLine, Qt::DashDotDotLine };
|
||||
QVector<Qt::PenStyle> pens {Qt::SolidLine, Qt::DashLine, Qt::DotLine, Qt::DashDotLine, Qt::DashDotDotLine };
|
||||
int ipen=0;
|
||||
for (int symbolID=0; symbolID<=JKQTPmaxSymbolID; symbolID++) {
|
||||
// generate some plot data
|
||||
@ -43,9 +43,18 @@ int main(int argc, char* argv[])
|
||||
// set symbol + pen style and color
|
||||
graph->set_symbol(static_cast<JKQTPgraphSymbols>(symbolID));
|
||||
graph->set_style(pens[ipen]);
|
||||
QString lname=JKQTP_QPenStyle2String(graph->get_style());
|
||||
graph->set_drawLine(static_cast<JKQTPgraphSymbols>(symbolID)!=JKQTPdot);
|
||||
if (!graph->get_drawLine()) lname="";
|
||||
// set symbol size
|
||||
graph->set_symbolSize(14);
|
||||
// set width of symbol lines
|
||||
graph->set_symbolWidth(1.5);
|
||||
// set width of graph line
|
||||
graph->set_lineWidth(1);
|
||||
|
||||
// graph title is made from symbol+penstyle
|
||||
graph->set_title(JKQTPgraphSymbols2NameString(static_cast<JKQTPgraphSymbols>(graph->get_symbol()))+QString(", ")+JKQTP_QPenStyle2String(graph->get_style()));
|
||||
graph->set_title(JKQTPgraphSymbols2NameString(static_cast<JKQTPgraphSymbols>(graph->get_symbol()))+QString(", ")+lname);
|
||||
|
||||
// add the graph to the plot, so it is actually displayed
|
||||
plot.addGraph(graph);
|
||||
|
Loading…
Reference in New Issue
Block a user