# Line graph

**URL:** <https://forum.juce.com/t/line-graph/5842>\
**Category:** General JUCE discussion\
**Created:** [November 3, 2010, 7:58pm UTC](https://forum.juce.com/t/line-graph/5842 "2010-11-03T19:58:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![billythekid](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/billythekid/32/88_2.png) [@billythekid](https://forum.juce.com/u/billythekid)\
**Post date:** [November 3, 2010, 7:58pm UTC](https://forum.juce.com/t/line-graph/5842/1 "2010-11-03T19:58:31Z")

</div>

Hey all,  
Another newbie question. What is the most simple way to put a plot into a component? Just a simple line graph. The simpler the better. It doesn’t need to update very often. All suggestions welcomed. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 3, 2010, 9:07pm UTC](https://forum.juce.com/t/line-graph/5842/2 "2010-11-03T21:07:37Z")

</div>

Just draw the lines… Use a Path, add your lines to it, then draw a stroke along it.

---

<div class="post-metadata">

**Author:** ![billythekid](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/billythekid/32/88_2.png) [@billythekid](https://forum.juce.com/u/billythekid)\
**Post date:** [November 3, 2010, 9:55pm UTC](https://forum.juce.com/t/line-graph/5842/3 "2010-11-03T21:55:56Z")

</div>

Thanks for the nudge in the right direction. I was looking at this for some inspiration . . .

[http://code.google.com/p/dspfilterscpp/source/browse/trunk/DspJuceDemo.cpp](http://code.google.com/p/dspfilterscpp/source/browse/trunk/DspJuceDemo.cpp)

. . . but using that source I was getting build errors that I was unable to fix with my current level of C++ competence. Anyhow, I found the Doxygen Path page and should be able to cobble something together from there. Many thanks.

---

<div class="post-metadata">

**Author:** ![billythekid](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/billythekid/32/88_2.png) [@billythekid](https://forum.juce.com/u/billythekid)\
**Post date:** [November 4, 2010, 5:08pm UTC](https://forum.juce.com/t/line-graph/5842/4 "2010-11-04T17:08:03Z")

</div>

Hi again. This is actually going surprisingly well ( shock :!: ) but I am having some trouble putting the icing on the cake. I would like to make a dashed line (I’m guessing using PathStrokeType::createDashedStroke) but I can’t get it to work for the life of me. Could anyone enlighten me with the magic line of code required to make a dashed line from the following code snippet.

`Path linReference;
 linReference.startNewSubPath (0, getHeight());
linReference.lineTo (getWidth(), 0);
g.setColour (Colours::cornflowerblue.withAlpha (0.5f));
 g.strokePath (linReference, PathStrokeType (3.0f));`

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 4, 2010, 6:53pm UTC](https://forum.juce.com/t/line-graph/5842/5 "2010-11-04T18:53:47Z")

</div>

You’d need to call PathStrokeType::createDashedStroke to generate a new path from your original one, then you’d just fill the new path.

---

<div class="post-metadata">

**Author:** ![billythekid](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/billythekid/32/88_2.png) [@billythekid](https://forum.juce.com/u/billythekid)\
**Post date:** [November 4, 2010, 8:56pm UTC](https://forum.juce.com/t/line-graph/5842/6 "2010-11-04T20:56:14Z")

</div>

> [@jules](#):
>
> You’d need to call PathStrokeType::createDashedStroke to generate a new path from your original one, then you’d just fill the new path.

Easily said 🙂 . Well, after hacking away at this and being greeted with a whole new bunch of compile errors that I’ve not seen before (it has been a good learning expirience), I have managed to get something working.

```auto
Path linReference;
linReference.startNewSubPath (0, getHeight());
linReference.lineTo (getWidth(), 0);

PathStrokeType *dasher;	   
dasher = new PathStrokeType(3.0);
float Dashes[] = { 20, 10 };
dasher->createDashedStroke(linReference, linReference, Dashes, 2);

g.setColour (Colours::cornflowerblue.withAlpha (0.5f));
g.strokePath (linReference, PathStrokeType (3.0f));
```

Is that the right kind of idea or have I just made code spaghetti? Ta much. PS Juce is awesome!

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 4, 2010, 10:05pm UTC](https://forum.juce.com/t/line-graph/5842/7 "2010-11-04T22:05:05Z")

</div>

You’re leaking like a sieve there. Never use ‘new’ if you can use a stack object instead.

More like this:

[code]Path linReference;  
linReference.startNewSubPath (0, getHeight());  
linReference.lineTo (getWidth(), 0);

float Dashes = { 20, 10 };  
PathStrokeType (3.0f).createDashedStroke (linReference, linReference, Dashes, 2);

g.setColour (Colours::cornflowerblue.withAlpha (0.5f));  
g.fillPath (linReference);[/code]

---

<div class="post-metadata">

**Author:** ![billythekid](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/billythekid/32/88_2.png) [@billythekid](https://forum.juce.com/u/billythekid)\
**Post date:** [November 4, 2010, 10:46pm UTC](https://forum.juce.com/t/line-graph/5842/8 "2010-11-04T22:46:08Z")

</div>

AHA! That looks more elegant 🙂 Sorry to make your eyes bleed with my code. Anyhow, the plot is up, running, and most importantly functioning as expected. Joy.

Thanks again.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 5, 2010, 9:08am UTC](https://forum.juce.com/t/line-graph/5842/9 "2010-11-05T09:08:20Z")

</div>

> [@](#):
>
> Sorry to make your eyes bleed with my code.

I’ve seen far worse atrocities than that on the pages of this forum!
