CSS: Formatting Visual Data
Illustration by John Hersey

CSS: Formatting Visual Data

with Joseph Lowery

Video: Building bar charts

The first thing that comes to mind when you hear the term, visual data, may very well be charts. Throughout this chapter, we'll take a look at ways to visualize data through a number of different graphs. Our first type covered in this lesson is the bar chart. Of course, you can create a bar chart, or any other type of chart in a graphics program like Photoshop. But it's far more interesting for the web designer to do it where you have a larger measure of control. And can change it at the drop of a client's hat.

Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now
please wait ...
Watch the Online Video Course CSS: Formatting Visual Data
1h 37m Intermediate Mar 26, 2013

Viewers: in countries Watching now:

Having a complete toolbox at your disposal to properly structure and display data is critically important to a successful web design. In this course, author Joseph Lowery covers basic styling for numbered, bulleted, and definition lists, plus structuring and formatting tables with CSS. He also includes instructions on creating charts and graphs with the HTML5 Canvas element. Each section of the course highlights advanced CSS, HTML5, and JavaScript techniques that increase interactivity, yield responsive designs, and heighten the user experience.

Topics include:
  • Adding custom number characters to lists
  • Managing hanging indents
  • Styling nested lists
  • Understanding definition lists
  • Highlighting table content
  • Creating alternating row colors (zebra stripes)
  • Building bar graphs and pie charts
Subject:
Web
Software:
CSS
Author:
Joseph Lowery

Building bar charts

The first thing that comes to mind when you hear the term, visual data, may very well be charts. Throughout this chapter, we'll take a look at ways to visualize data through a number of different graphs. Our first type covered in this lesson is the bar chart. Of course, you can create a bar chart, or any other type of chart in a graphics program like Photoshop. But it's far more interesting for the web designer to do it where you have a larger measure of control. And can change it at the drop of a client's hat.

For that, we need to turn to the HTML 5 innovation canvas. Canvas objects are drawn programmatically through java script, which means it's much easier to change the things like the data values and labels. For this chart, I'm going to use a code developed by a gentleman named William Malone, and available on his site. Let's start. The first task is to link to the Java script file that contains the majority of the functionality. I'm going to place my cursor after the link to main.css. And enter the needed script tag.

I'll set the source to my scripts folder. Where I've already downloaded HTML5-canvas-bar-graph.js. Now let me set the type to text JavaScript and close the tag. Now I am going to scroll down the page a little bit just to point out a div that we have on line 36. You'll see a div there already marked up with the id of bar chart. That is where our bar chart is going to go.

Let's go do to the bottom of the page, and we'll put in the script tag that we'll call all the canvas drawing functions. I am going to place this just above the closing body tag and I'll start by entering a script tag, and then in the center create a little space. Because we're not using jQuery or its equivilent, we don't have something like the jQuery document ready function, so we'll need to wrap the entire fucntion in parantheses. After I type in the word function, I'll enter another set of parenthese. And then following that between the two closing parenthesis, I'll put in my curly brace pair, and hit return to open up a line. Next, we'll create the canvas object.

So I'll enter in var and I'm going to call this variable CTX, and set that equal to, Create Canvas this is a function that's in the library that we link to. And we'll give it the name of the divs ID, bar chart, so we can tell where to place that canvas. On the next line we'll create a new bar graph object, and I'm just going to call this graph, and set that equal to new bar graph and will use the canvass CTX.

Now we need to specify a good number of values. First, we'll set the maximum value and we'll target graph the property max value, and make that 1,000. Then the margin between each of the bars, I'm going to set the graph.margin equal to 5. Next up the colors will be defined in an array. For an array we'll use the square brackets.

And each value within it is a string, so it'll be contained within a pair of quotes. All of these values that I'll enter are six digit hexadecimal numbers, 0263ae is the first one. Next will be a858a3. Our next colored number, fbae2c, and then the final one, df4c27. Let's close off that entire array with a semicolon, and now we're ready for the labels.

These particular labels will go along the x axis, so x axis Label Arr, short for array, and for an array we'll use the square brackets. And the first in the array is Painting, followed by Sculpture, next Digital, and then Studio. Don't forget your closing semicolon. Our final line are the values that we want to pass in for the data.

And for that we use the method update. And because it's a method, a set of parenthesis follows it. And within it, the square brackets of the array. These are number values so they don't need quotes. So Painting is 950, Sculpture 650, Digital 700, and Studio 885. Looks like I need to add another pair of parentheses here, following the function call, and a closing semi-colon. Let's Save the file and Browse it. As you can see, this bar chart has gradients built in to give it a very polished result.

If you change the number of elements in the array, you can alter the number of bars shown. All in all, I think it's a pretty flexible, easy to use system, and I hope you find it so.

There are currently no FAQs about CSS: Formatting Visual Data.

 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

* Estimated file size

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed CSS: Formatting Visual Data.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.