2 Replies - 2389 Views - Last Post: 15 December 2014 - 12:10 AM Rate Topic: -----

#1 airukraine1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 20-October 14

Merging multiple charts into one chart (different y-axis)

Posted 14 December 2014 - 03:08 AM

Hello,

I have successfully programmed code that can activate different chart information from my program. My program is basically a Bench Press workout graphing overview of a user's progress. The user enters Weight Lifted, Mood that the user felt throughout the daily lifts, how much Sleep he has gotten, Calories eaten. This information has each individual graph that graphs it as information is stored in database and pulled out subsequently when the user wants to see how it looks ( through a Line Chart).

The problem, and this would be one of the greatest solutions ever devised, is to actually combine all the different Y-ranges( since Calories ranges from 0-5000, Sleep ranges from (0-10), Mood ranges from (1-5), and Weight ranges from 0-500) into one graph that LOOKS GOOD. I have combined all the graphs together, but the ranges for Mood, and Sleep are way too small, and therefore disappear in the graph, compared to the Calories range which reaches up to 5000!

If anybody can, please help me make the graph

This is the combo graph (clicked on by "All" button). As you can see, Mood and Sleep are hidden because their data is way too small!

Posted Image



This is the code for the ALL combo graph using a function stored in a separate business class for each Button (which user clicks on, function is activated, and the information is displayed on the graph associated with what the user clicked on)



Public Sub AllGraph(ByRef mainChart As Chart)

        mainChart.Series.Clear()

        Dim strConn As String = "Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\User\Documents\Visual Studio 2012\ Projects\Project\Project\Real Project\RealProject\database\Database1.mdf;Integrated Security=True"

        Dim conn As New SqlConnection(strConn)

        Dim sqlUserData As String = "SELECT Day, Weight, Calories, Mood, Sleep FROM dbo.UserData  WHERE DATEDIFF(Day,[Day],GETDATE()) <=7 ORDER By Day DESC "
        Dim da As New SqlDataAdapter(sqlUserData, conn)
        Dim ds As New DataSet()
        da.Fill(ds, "UserData")

        mainChart.DataSource = ds.Tables("UserData")

        mainChart.Series.Add("Weight").ChartType = SeriesChartType.Line
        mainChart.Series.Add("Calories(x100)").ChartType = SeriesChartType.Line
        mainChart.Series.Add("Mood(/100)").ChartType = SeriesChartType.Line
        mainChart.Series.Add("Sleep(/100)").ChartType = SeriesChartType.Line

        mainChart.ChartAreas(0).AxisX.Interval = 0
        mainChart.TabIndex = 0
        mainChart.Text = "All"

        mainChart.Series("Weight").XValueMember = "Day"
        mainChart.Series("Weight").YValueMembers = "Weight"
        mainChart.Series("Calories(x100)").XValueMember = mainChart.Series("Weight").XValueMember
        mainChart.Series("Calories(x100)").YValueMembers = "Calories"

        mainChart.Series("Mood(/100)").XValueMember = "Day"
        mainChart.Series("Mood(/100)").YValueMembers = "Mood"
        mainChart.Series("Sleep(/100)").XValueMember = mainChart.Series("Weight").XValueMember
        mainChart.Series("Sleep(/100)").YValueMembers = "Sleep"
    End Sub


The Legends which are coded under "MainChart.Series("Mood/100") was just a testing to see if I need to reduce the Mood and Sleep by a 100 to scale it properly. If that is how its supposed to be done, please show me the steps and the code to achieve that. If not, I'm sure there is another solution.

It would be much appreciated, ASAP, if someone can help me figure out a way to scale them all together. I ran out of ideas on how to make it scale in a PERFECT manner so that user can see his weight progress and how his mood, sleep, and calories progressed during his week that he lifted. Thank you so much for your help!

---

Additionally, I also cannot figure out a way to OVERLAY each of the 4 bottom buttons clicked on (Mood, Weight, Sleep, Calories) one by one. Basically, if user clicks on "Mood" button, I want it to graph two line graphs overlayed next to Weight graph. Else if user clicks "Mood, Sleep", then I want to that to overlayed on top of Weight line graph. Basically each variable the user clicks on, I want it to be overlayed so that the user doesn't have to click "All" button to see all 4 variables put together! Thanks again!

Is This A Good Question/Topic? 0
  • +

Replies To: Merging multiple charts into one chart (different y-axis)

#2 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6735
  • View blog
  • Posts: 27,712
  • Joined: 12-December 12

Re: Merging multiple charts into one chart (different y-axis)

Posted 14 December 2014 - 05:55 AM

In Excel we can create a secondary axis:

Attached Image

I assume we can do the same thing in VB so you could search "vb.net chart secondary axis".

Alternatively, if sleep and mood have arbitrarily assigned values, then you might multiply them by 100.

If overlaying (your other request) would result in a graph similar to this - with several series - then you need to sort the display issue first. Overlaying would essentially just involve adding and removing series.
Was This Post Helpful? 0
  • +
  • -

#3 airukraine1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 20-October 14

Re: Merging multiple charts into one chart (different y-axis)

Posted 15 December 2014 - 12:10 AM

Hi Andrew,

thanks for your help.

I researched it and ended up here: http://www.vbforums....source-is-table

Basically, the user said that adding this line of code:

ChartResults.Series("SomeSeriesName").YAxisType = AxisType.Secondary


did the trick for him, and it worked.


-
So what I am trying to achieve is this:

Step 1) User clicks "Weight" button first, which shows his weight data for that week
Step 2) User clicks "Mood" button next, which SHOULD show his Weight data and his Mood data next to each other, with
two distinct line graphs.

In Step 2, that is where in my function for "Mood" button, I added the code that I found, which turns out like this. The bolded code is what I found and added to make "Weight" a secondary Y-axis:


Public Sub MoodGraph(ByRef mainChart As Chart)
        mainChart.Series.Clear()
        'passChart = mainChart

        Dim strConn As String = "Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\User\Kitties\Visual Studio 2012\Projects\Project\Project\Project\Project\database\Database1.mdf;Integrated Security=True"

        Dim conn As New SqlConnection(strConn)

        Dim sqlUserData As String = "SELECT * FROM dbo.UserData  WHERE DATEDIFF(Day,[Day],GETDATE()) <=7 ORDER By Day DESC "
        Dim da As New SqlDataAdapter(sqlUserData, conn)
        Dim ds As New DataSet()
        da.Fill(ds, "UserData")

        mainChart.DataSource = ds.Tables("UserData")

        mainChart.Series.Add("Mood").ChartType = SeriesChartType.Line
       [b] mainChart.Series.Add("Weight").ChartType = SeriesChartType.Line[/b]

        mainChart.Series("Mood").XValueMember = "Day"
        mainChart.Series("Mood").YValueMembers = "Mood"
        'mainChart.Series("Weight").XAxisType = AxisType.Secondary
        [b]mainChart.Series("Sleep").YAxisType = AxisType.Secondary[/b]


Problem is that when I click on the Mood chart, it just shows the line chart for Mood, it doesn't add the
secondary axis of "Weight."

Here is the pic for just "Weight" button clicked and Weight shown.

Posted Image


Here is the pic for "Mood" button clicked, the "Weight" series is added as seen in the legend, but the "Weight"
graph is not shown next to Mood data. Why?

Posted Image

Oops, I don't want to confuse you..

this code:

[b]mainChart.Series("Sleep").YAxisType = AxisType.Secondary[/b]


Should be:

[b]mainChart.Series("Weight").YAxisType = AxisType.Secondary[/b]



It was correct in my code, I just didn't change it when I posted it. Thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1