How to loop through data to generate charts

gshock

New Member
Joined
Jan 26, 2013
Messages
37
Office Version
  1. 365
Platform
  1. Windows
How do I loop through data to create a chart with multiple Series. Then, how to I repeat that to create multiple charts, using that same methodology for the rest of the data?

Below is a table of fictional data, but the order of indexing is real. That is, at a given speed, suction pressure is held constant, and discharge pressure is increased. A program calculates the required HP. The suction pressure is increased, speed is still constant, and the discharge pressure is incremented, and HP is calculated.

Then the speed is increased to the next interval, and the process is repeated. I'm trying to figure out a way to loop through the day and create a chart for each speed range. In reality, there are too many data points to create all of the series on one chart. So I want to create the charts based on speed. I'm struggling with how to lay out the format for this. Should i used nested FOR loops? Should I use a Case structure? What's the best way to go about it? I haven't learned enough about Chart objects yet to understand how to populate a series using VBA.

I'm not looking for someone to do this for me. I really want to learn, and I'm only asking for guidance. Thank you in advance.


speedPsuctionPdischargePower
100100500750.00
100100505756.25
100100510762.50
100100515768.75
100100520775.00
100100525781.25
100100530787.50
100100535793.75
100100540800.00
100100545806.25
100100550812.50
100105500750.00
100105505756.25
100105510762.50
100105515768.75
100105520775.00
100105525781.25
100105530787.50
100105535793.75
100105540800.00
100105545806.25
100105550812.50
100110500750.00
100110505756.25
100110510762.50
100110515768.75
100110520775.00
100110525781.25
100110530787.50
100110535793.75
100110540800.00
100110545806.25
100110550812.50
200100500875.00
200100505881.25
200100510887.50
200100515893.75
200100520900.00
200100525906.25
200100530912.50
200100535918.75
200100540925.00
200100545931.25
200100550937.50
200105500875.00
200105505881.25
200105510887.50
200105515893.75
200105520900.00
200105525906.25
200105530912.50
200105535918.75
200105540925.00
200105545931.25
200105550937.50
200110500875.00
200110505881.25
200110510887.50
200110515893.75
200110520900.00
200110525906.25
200110530912.50
200110535918.75
200110540925.00
200110545931.25
200110550937.50
3001005001000.00
3001005051006.25
3001005101012.50
3001005151018.75
3001005201025.00
3001005251031.25
3001005301037.50
3001005351043.75
3001005401050.00
3001005451056.25
3001005501062.50
3001055001000.00
3001055051006.25
3001055101012.50
3001055151018.75
3001055201025.00
3001055251031.25
3001055301037.50
3001055351043.75
3001055401050.00
3001055451056.25
3001055501062.50
3001105001000.00
3001105051006.25
3001105101012.50
3001105151018.75
3001105201025.00
3001105251031.25
3001105301037.50
3001105351043.75
3001105401050.00
3001105451056.25
3001105501062.50
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
How do I loop through data to create a chart with multiple Series. Then, how to I repeat that to create multiple charts, using that same methodology for the rest of the data?

Below is a table of fictional data, but the order of indexing is real. That is, at a given speed, suction pressure is held constant, and discharge pressure is increased. A program calculates the required HP. The suction pressure is increased, speed is still constant, and the discharge pressure is incremented, and HP is calculated.

Then the speed is increased to the next interval, and the process is repeated. I'm trying to figure out a way to loop through the day and create a chart for each speed range. In reality, there are too many data points to create all of the series on one chart. So I want to create the charts based on speed. I'm struggling with how to lay out the format for this. Should i used nested FOR loops? Should I use a Case structure? What's the best way to go about it? I haven't learned enough about Chart objects yet to understand how to populate a series using VBA.

I'm not looking for someone to do this for me. I really want to learn, and I'm only asking for guidance. Thank you in advance.


speedPsuctionPdischargePower
100100500750.00
100100505756.25
100100510762.50
100100515768.75
100100520775.00
100100525781.25
100100530787.50
100100535793.75
100100540800.00
100100545806.25
100100550812.50
100105500750.00
100105505756.25
100105510762.50
100105515768.75
100105520775.00
100105525781.25
100105530787.50
100105535793.75
100105540800.00
100105545806.25
100105550812.50
100110500750.00
100110505756.25
100110510762.50
100110515768.75
100110520775.00
100110525781.25
100110530787.50
100110535793.75
100110540800.00
100110545806.25
100110550812.50
200100500875.00
200100505881.25
200100510887.50
200100515893.75
200100520900.00
200100525906.25
200100530912.50
200100535918.75
200100540925.00
200100545931.25
200100550937.50
200105500875.00
200105505881.25
200105510887.50
200105515893.75
200105520900.00
200105525906.25
200105530912.50
200105535918.75
200105540925.00
200105545931.25
200105550937.50
200110500875.00
200110505881.25
200110510887.50
200110515893.75
200110520900.00
200110525906.25
200110530912.50
200110535918.75
200110540925.00
200110545931.25
200110550937.50
3001005001000.00
3001005051006.25
3001005101012.50
3001005151018.75
3001005201025.00
3001005251031.25
3001005301037.50
3001005351043.75
3001005401050.00
3001005451056.25
3001005501062.50
3001055001000.00
3001055051006.25
3001055101012.50
3001055151018.75
3001055201025.00
3001055251031.25
3001055301037.50
3001055351043.75
3001055401050.00
3001055451056.25
3001055501062.50
3001105001000.00
3001105051006.25
3001105101012.50
3001105151018.75
3001105201025.00
3001105251031.25
3001105301037.50
3001105351043.75
3001105401050.00
3001105451056.25
3001105501062.50
Have you got an idea of what you want the chart to look like for any particular speed?

Can you produce one for us to look at?
 
Upvote 0
Have you got an idea of what you want the chart to look like for any particular speed?

Can you produce one for us to look at?
Indeed, I can...

See below. Thanks.

1729277033386.png
 
Upvote 0
Indeed, I can...

See below. Thanks.

View attachment 118255
I have put something together that may help you.

The raw data is in a table named tblRawChartData

In another sheet I have put this grid together from which the chart will get its data.

A drop down list in cell A1 enables the speed to be selected.

The chart changes when the speed is selected.

This just uses one chart.

You could create seperate charts for each speed and hard code the speed into the grid formula.

Cell Formulas
RangeFormula
C3:C13C3=UNIQUE(FILTER(tblRawChartData[Pdischarge],tblRawChartData[speed]=$A$1,""))
D3:F13D3=SUMIFS(tblRawChartData[Power],tblRawChartData[speed],$A$1,tblRawChartData[Psuction],D$2,tblRawChartData[Pdischarge],$C3)
Dynamic array formulas.
Cells with Data Validation
CellAllowCriteria
A1List100,200,300


1729327970136.png
 
Upvote 0
I have put something together that may help you.

The raw data is in a table named tblRawChartData

In another sheet I have put this grid together from which the chart will get its data.

A drop down list in cell A1 enables the speed to be selected.

The chart changes when the speed is selected.

This just uses one chart.

You could create seperate charts for each speed and hard code the speed into the grid formula.

Cell Formulas
RangeFormula
C3:C13C3=UNIQUE(FILTER(tblRawChartData[Pdischarge],tblRawChartData[speed]=$A$1,""))
D3:F13D3=SUMIFS(tblRawChartData[Power],tblRawChartData[speed],$A$1,tblRawChartData[Psuction],D$2,tblRawChartData[Pdischarge],$C3)
Dynamic array formulas.
Cells with Data Validation
CellAllowCriteria
A1List100,200,300


View attachment 118276

That's not exactly what I was looking for, but that has some really interesting functionality that I could use for other things. Great job. Thank you.

If my goal is to populate series data using the X-axis and Y-axis values, how would I create the Legend Entries for the series, and the Series ranges? If the chart container in excel is for holding the chart object, are there other properties or methods to the chart that hold the chart elements?
 
Upvote 0
Have you created a table from your data and set up the grid representing the X and Y axis for each series?

If you have then have you created a chart from this data?

The grid calculates the series data for the chart.

The Legend comes from the column headings on this grid.

How did you get the Legend on the chart that you posted in Post 3?

When you have created the chart you can click on any of the elements (Title, X and Y Axis, Legend and each Series) and change the properties.
Apart from Chart Title, all of the elements on the chart in Post 3.

It would be useful if you can post some realistic data using XL2BB.
 
Upvote 0
Have you created a table from your data and set up the grid representing the X and Y axis for each series?

If you have then have you created a chart from this data?

The grid calculates the series data for the chart.

The Legend comes from the column headings on this grid.

How did you get the Legend on the chart that you posted in Post 3?

When you have created the chart you can click on any of the elements (Title, X and Y Axis, Legend and each Series) and change the properties.
Apart from Chart Title, all of the elements on the chart in Post 3.

It would be useful if you can post some realistic data using XL2BB.
I created the charts manually, which I have done many times. I set up the chart titles, axis titles, and series data as I needed them using the green "+" to the right of the chart. But I have so much data that I can't put it all on one chart. Because I have to create more than a few charts, it's not practical to have one chart that updates based on the dropdown selection (although, that's a really cool idea!).

I'm still learning VBA, but I know how to create new sheets in a workbook. I created the charts manually, and changed them from an object in a sheet to a new sheet with the speed name. Since that was a repetitious process, I figured I could automate it with VBA to loop through the data and define the X-axis and Y-axis values. I assumed that all I would need to do is identify the chart object somehow and then work with the properties or method of that object. Then, I planned to loop through the charts (collection?)
 
Upvote 0
I created the charts manually, which I have done many times. I set up the chart titles, axis titles, and series data as I needed them using the green "+" to the right of the chart. But I have so much data that I can't put it all on one chart. Because I have to create more than a few charts, it's not practical to have one chart that updates based on the dropdown selection (although, that's a really cool idea!).

I'm still learning VBA, but I know how to create new sheets in a workbook. I created the charts manually, and changed them from an object in a sheet to a new sheet with the speed name. Since that was a repetitious process, I figured I could automate it with VBA to loop through the data and define the X-axis and Y-axis values. I assumed that all I would need to do is identify the chart object somehow and then work with the properties or method of that object. Then, I planned to loop through the charts (collection?)
You only need to create one chart which is used irrespective of what speed you need it to represent.

It is the values in the data ranges that the chart references that change. That is what the drop down is used for.

You don't need the drop down but you need to indicate somehow which speed you want the chart to use.

Examine the grid and see what the formula are achieving.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top