Home Blog Page 5

C3.js – A D3 based reusable chart library with deeper integration with applications dynamic data

C3.js –  A D3 based reusable chart library with deeper integration with applications dynamic data

//

Comfortable

C3 makes it easy to generate D3-based charts by wrapping the code required to construct the entire chart. We don’t need to write D3 code any more.

Customizable

C3 gives some classes to each element when generating, so you can define a custom style by the class and it’s possible to extend the structure directly by D3.

Controllable

C3 provides a variety of APIs and callbacks to access the state of the chart. By using them, you can update the chart even if after it’s rendered.

c3js

 C3.js | D3-based reusable chart library//

In this guide, we are going to show you how to get started with C3.

1. Setup

Download the latest version here:

Installing by Bower/Component is also available with the name c3.

Then, load the scripts and css:

<!-- Load c3.css -->
<link href="/path/to/c3.css" rel="stylesheet" type="text/css">

<!-- Load d3.js and c3.js -->
<script src="/path/to/d3.v3.min.js" charset="utf-8"></script>
<script src="/path/to/c3.min.js"></script>

C3 depends on D3, so please load D3 too.


2. Generate Chart

C3 generates a chart by calling generate() with the argument object, and an element including the chart will insert into the element specified as a selector in that argument as bindto.

Prepare the element to bind the chart:

<div id="chart"></div>

And, call generate() with arguments:

var chart = c3.generate({
    bindto: '#chart',
    data: {
      columns: [
        ['data1', 30, 200, 100, 400, 150, 250],
        ['data2', 50, 20, 10, 40, 15, 25]
      ]
    }
});

C3 supports the asynchronous module definition (AMD) API. If you use RequireJS, you can load like this:

require.config({
  baseUrl: '/js',
  paths: {
    d3: "http://d3js.org/d3.v3.min"
  }
});

require(["d3", "c3"], function(d3, c3) {
  c3.generate({
    ...
  });
});

Then, you will see the chart:

 

 

Examples:

 

C3.js | D3-based reusable chart library//

# Chart

Line Chart

Line chart with sequential data.

View details »

Timeseries Chart

Simple line chart with timeseries data.

View details »

Spline Chart

Display as Spline Chart.

View details »

Simple XY Line Chart

Simple line chart with custom x.

View details »

Multiple XY Line Chart

Multiple line chart with multiple custom x.

View details »

Line Chart with Regions

Set regions for each data with style.

View details »

Step Chart

Display as Step Chart.

View details »

Area Chart

Display as Area Chart.

View details »

Stacked Area Chart

Display as Stacked Area Chart.

View details »

Bar Chart

Display as Bar Chart.

View details »

Stacked Bar Chart

Display as Stacked Bar Chart.

View details »

Scatter Plot

Display as Scatter Plot.

View details »

Pie Chart

Display as Pie Chart.

View details »

Donut Chart

Display as Donut Chart.

View details »

Gauge Chart

Display as Gauge Chart.

View details »

Combination Chart

Display all kinda charts up in here.

View details »


# Axis

Category Axis

Show ticks as categorized by each data.

View details »

Rotated Axis

Switch x and y axis position.

View details »

Additional Y Axis

Additional y axis can be added.

View details »

X Axis Tick Format

Format x axis tick text.

View details »

X Axis Tick Count

Set the number of ticks on X Axis.

View details »

X Axis Tick Values

Set tick texts on X Axis.

View details »

X Axis Tick Culling

Set cull ticks or not on X Axis.

View details »

X Axis Tick Fitting

Set ticks position to x of data.

View details »

X Axis Timezone

Convert time to UTC.

View details »

Rotate X Axis Tick Text

Rotate x axis tick text.

View details »

Y Axis Tick Format

Format y axis tick text.

View details »

Padding for Y Axis

Set padding for y axis.

View details »

Range for Y Axis

Set range for y axis.

View details »

Axis Label

Set label for axis.

View details »

Axis Label Position

Set axis label position.

View details »


# Data

Column Oriented Data

Column-oriented data can be used as input.

View details »

Row Oriented Data

Row-oriented data can be used as input.

View details »

JSON Data

JSON can be used as input.

View details »

Data from URL

Data from URL can be used as input.

View details »

Category Data

Load data with x values on category axis.

View details »

Load Data

Load data dynamically.

View details »

Data Name

Set name for each data.

View details »

Data Color

Set color according to data.

View details »

Data Order

Define data order. This will be used for stacked bar chart.

View details »

Data Label

Show label of data.

View details »

Data Label Format

Format label of data.

View details »


# Grid

Grid Lines

Show grid lines for x and y axis.

View details »

Optional X Grid Lines

Add optional grid lines on x grid.

View details »

Optional Y Grid Lines

Add optional grid lines on y grid.

View details »


# Region

Region

Show rects on chart.

View details »

Region with Timeseries

Show rects on timeseries chart.

View details »


# Interaction

Sub Chart

Show sub chart for zoom and selection range.

View details »

Zoom

Zoom by mouse wheel event and slide by drag.

View details »


# Legend

Hide Legend

Set visibility of legend.

View details »

Legend Position

Show legend on bottom or right side.

View details »

Custom Legend

Build custom legend

View details »


# Tooltip

Hide Tooltip

Set visibility of tooltip.

View details »

Tooltip Grouping

Show tooltips as grouped or not.

View details »

Tooltip Format

Set format for title and value on tooltip.

View details »


# Chart Options

Chart Size

Set chart size in px.

View details »

Padding

Change padding for the chart.

View details »

Color Pattern

Set custom color pattern.

View details »

Duration of Transition

Set duration of transition for chart animation.

View details »


# Line Chart Options

Hide points

Hide points on line chart

View details »


# Pie Chart Options

Pie Label Format

Change label format on Pie chart

View details »


# API

Flow

Load/Unload data as flowing

View details »

Data Name

Update data names.

View details »

Data Color

Update data colors.

View details »

Axis Label

Update axis labels.

View details »

Axis Range

Update axis range.

View details »

Resize

Resize chart.

View details »

X Grid

Update custom x grids.

View details »


# Transform

To Line Chart

Transform to line chart.

View details »

To Spline Chart

Transform to spline chart.

View details »

To Bar Chart

Transform to bar chart.

View details »

To Area Chart

Transform to area chart.

View details »

To Area Spline Chart

Transform to area spline chart.

View details »

To Scatter Plot

Transform to scatter plot.

View details »

To Pie Chart

Transform to pie chart.

View details »

To Donut Chart

Transform to donut chart.

View details »


# Style

Style for Region

Set style for regions.

View details »

Style for Grid

Set style for grids.

View details »



Thanks for reading,

SABIT SOLUTIONS

Chart.js – A Sleek, Simple, clean and engaging HTML5 based charts for designers and developers

Chart.js – A Sleek, Simple, clean and engaging HTML5 based charts for designers and developers

Chart.js | Open source HTML5 Charts for your website

Everything you need to know to build great looking charts using Chart.js

Six chart types

Visualize your data in 6 different ways. Each of them animated, with a load of customisation options and interactivity extensions.

HTML5 based

<canvas>

Chart.js uses the HTML5 canvas element. It’s supported in all modern browsers, and polyfills support for IE7/8.

Simple and flexible

Chart.js is dependency free and super lightweight. All six core chart types are only 11.01kb when minified, concatenated and served gzipped.

Responsive new

Artboard 1

Chart.js will resize your chart if the browser changes size, along with providing the perfect scale granularity for that size

Modular new

  • Core
  • Bar
  • Doughnut
  • Radar
  • Line
  • Polar Area

Chart.js is modular, and each of the chart types have been split up, so you can load only which chart types you need for your project

Interactive new

Chart.js provides default simple support for canvas tooltips on hover/touch, but you can extend chart interactions to trigger events in your application

 

Chart.js | Documentation//

Creating a chart

To create a chart, we need to instantiate the Chart class. To do this, we need to pass in the 2d context of where we want to draw the chart. Here’s an example.

<canvas id="myChart" width="400" height="400"></canvas>
// Get the context of the canvas element we want to select
var ctx = document.getElementById("myChart").getContext("2d");
var myNewChart = new Chart(ctx).PolarArea(data);

We can also get the context of our canvas with jQuery. To do this, we need to get the DOM node out of the jQuery collection, and call the getContext("2d") method on that.

// Get context with jQuery - using jQuery's .get() method.
var ctx = $("#myChart").get(0).getContext("2d");
// This will get the first returned node in the jQuery collection.
var myNewChart = new Chart(ctx);

After we’ve instantiated the Chart class on the canvas we want to draw on, Chart.js will handle the scaling for retina displays.

With the Chart class set up, we can go on to create one of the charts Chart.js has available. In the example below, we would be drawing a Polar area chart.

new Chart(ctx).PolarArea(data, options);

We call a method of the name of the chart we want to create. We pass in the data for that chart type, and the options for that chart as parameters. Chart.js will merge the global defaults with chart type specific defaults, then merge any options passed in as a second argument after data.

Global chart configuration

This concept was introduced in Chart.js 1.0 to keep configuration DRY, and allow for changing options globally across chart types, avoiding the need to specify options for each instance, or the default for a particular chart type.

Chart.defaults.global = {
    // Boolean - Whether to animate the chart
    animation: true,

    // Number - Number of animation steps
    animationSteps: 60,

    // String - Animation easing effect
    animationEasing: "easeOutQuart",

    // Boolean - If we should show the scale at all
    showScale: true,

    // Boolean - If we want to override with a hard coded scale
    scaleOverride: false,

    // ** Required if scaleOverride is true **
    // Number - The number of steps in a hard coded scale
    scaleSteps: null,
    // Number - The value jump in the hard coded scale
    scaleStepWidth: null,
    // Number - The scale starting value
    scaleStartValue: null,

    // String - Colour of the scale line
    scaleLineColor: "rgba(0,0,0,.1)",

    // Number - Pixel width of the scale line
    scaleLineWidth: 1,

    // Boolean - Whether to show labels on the scale
    scaleShowLabels: true,

    // Interpolated JS string - can access value
    scaleLabel: "<%=value%>",

    // Boolean - Whether the scale should stick to integers, not floats even if drawing space is there
    scaleIntegersOnly: true,

    // Boolean - Whether the scale should start at zero, or an order of magnitude down from the lowest value
    scaleBeginAtZero: false,

    // String - Scale label font declaration for the scale label
    scaleFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",

    // Number - Scale label font size in pixels
    scaleFontSize: 12,

    // String - Scale label font weight style
    scaleFontStyle: "normal",

    // String - Scale label font colour
    scaleFontColor: "#666",

    // Boolean - whether or not the chart should be responsive and resize when the browser does.
    responsive: false,

    // Boolean - whether to maintain the starting aspect ratio or not when responsive, if set to false, will take up entire container
    maintainAspectRatio: true,

    // Boolean - Determines whether to draw tooltips on the canvas or not
    showTooltips: true,

    // Function - Determines whether to execute the customTooltips function instead of drawing the built in tooltips (See [Advanced - External Tooltips](#advanced-usage-custom-tooltips))
    customTooltips: false,

    // Array - Array of string names to attach tooltip events
    tooltipEvents: ["mousemove", "touchstart", "touchmove"],

    // String - Tooltip background colour
    tooltipFillColor: "rgba(0,0,0,0.8)",

    // String - Tooltip label font declaration for the scale label
    tooltipFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",

    // Number - Tooltip label font size in pixels
    tooltipFontSize: 14,

    // String - Tooltip font weight style
    tooltipFontStyle: "normal",

    // String - Tooltip label font colour
    tooltipFontColor: "#fff",

    // String - Tooltip title font declaration for the scale label
    tooltipTitleFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",

    // Number - Tooltip title font size in pixels
    tooltipTitleFontSize: 14,

    // String - Tooltip title font weight style
    tooltipTitleFontStyle: "bold",

    // String - Tooltip title font colour
    tooltipTitleFontColor: "#fff",

    // Number - pixel width of padding around tooltip text
    tooltipYPadding: 6,

    // Number - pixel width of padding around tooltip text
    tooltipXPadding: 6,

    // Number - Size of the caret on the tooltip
    tooltipCaretSize: 8,

    // Number - Pixel radius of the tooltip border
    tooltipCornerRadius: 6,

    // Number - Pixel offset from point x to tooltip edge
    tooltipXOffset: 10,

    // String - Template string for single tooltips
    tooltipTemplate: "<%if (label){%><%=label%>: <%}%><%= value %>",

    // String - Template string for multiple tooltips
    multiTooltipTemplate: "<%= value %>",

    // Function - Will fire on animation progression.
    onAnimationProgress: function(){},

    // Function - Will fire on animation completion.
    onAnimationComplete: function(){}
}

If for example, you wanted all charts created to be responsive, and resize when the browser window does, the following setting can be changed:

Chart.defaults.global.responsive = true;

Now, every time we create a chart, options.responsive will be true.

 

 


 

Source: https://github.com/nnnick/Chart.js

Documentation: http://www.chartjs.org/docs/#getting-started-creating-a-chart


 

 

Thanks,
SABIT SOLUTIONS

morris.js – Simple elegant looking Charts Library based on Javascript

morris.js – Simple elegant looking Charts Library based on Javascript

 

It’s a very simple API for drawing line, bar, area and donut charts.

Requirements

  • jQuery (>= 1.7 recommended, but it’ll probably work with older versions)
  • Raphael.js (>= 2.0)

 

Getting started

Add morris.js and its dependencies (jQuery &Raphaël) to your page.

1 <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css">
2 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
3 <script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
4 <script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>

If you don’t want to use the CDN-hosted assets, then you can extract them from the zip bundle and upload them to your own site.

 

morris.js

Your first chart

Start by adding a <div> to your page that will contain your chart. Make sure it has an ID so you can refer to it in your Javascript later.

<div id="myfirstchart" style="height: 250px;"></div>

Note: in order to display something, you’ll need to have given the div some dimensions. Here I’ve used inline CSS just for illustration.

Next add a <script> block to the end of your page, containing the following javascript code:

new Morris.Line({
  // ID of the element in which to draw the chart.
  element: 'myfirstchart',
  // Chart data records -- each entry in this array corresponds to a point on
  // the chart.
  data: [
    { year: '2008', value: 20 },
    { year: '2009', value: 10 },
    { year: '2010', value: 5 },
    { year: '2011', value: 5 },
    { year: '2012', value: 20 }
  ],
  // The name of the data record attribute that contains x-values.
  xkey: 'year',
  // A list of names of data record attributes that contain y-values.
  ykeys: ['value'],
  // Labels for the ykeys -- will be displayed when you hover over the
  // chart.
  labels: ['Value']
});

 


 

Website: http://morrisjs.github.io/morris.js/


 

Raphaël—JavaScript, SVG Library to simply vector graphics for websites.

Raphaël—JavaScript, SVG Library to simply vector graphics for websites.

Raphaël is a small JavaScript library that should simplify your work with vector graphics on the web.

If you want to create your own specific chart or image crop and rotate widget, for example, you can achieve it simply and easily with this library.

Raphaël [‘ræfeɪəl] uses the SVG W3C Recommendation and VML as a base for creating graphics. This means every graphical object you create is also a DOM object, so you can attach JavaScript event handlers or modify them later. Raphaël’s goal is to provide an adapter that will make drawing vector art compatible cross-browser and easy.

Raphaël currently supports Firefox 3.0+, Safari 3.0+, Chrome 5.0+, Opera 9.5+ and Internet Explorer 6.0+.

Raphaël Reference

var anim = Raphael.animation({cx: 10, cy: 20}, 2e3);
circle1.animate(anim); // run the given animation immediately
circle2.animate(anim.delay(500)); // run the given animation after 500 ms

http://raphaeljs.com/reference.html


Website: http://raphaeljs.com/

Example/DEMO: http://raphaeljs.com/analytics.html


Thanks,
SABIT SOLUTIONS

jVectorMap – Javascript, HTML, SVG based world, world regions, territories, countries MAPS plugin. Non-Flash, cross-browser interactive and customizable Maps!

 

jVectorMaps

 

jVectorMap – Javascript, HTML, SVG based world, world regions, territories, countries MAPS plugin. Non-Flash, cross-browser interactive and customizable Maps!

jVectorMap is a vector-based, cross-browser and cross-platform component for interactive geography-related data visualization on the web. It provides numerious features like smooth zooming and panning, fully-customizable styling, markers, labels and tooltips. No-Flash!
  • JavaScript-based

    jVectorMap uses only native browser technologies like JavaScript, CSS, HTML, SVG or VML. No Flash or any other proprietary browser plug-in is required. This allows jVectorMap to work in all modern mobile browsers.

  • Plug-in package includes maps converter written in Python. It’s used to create maps available on this site. If you want to create some custom map you can create it using data in common GIS formats like Shapefile for example.
  • Many maps of the world, world regions, countries and cities are available for download from this site. All of them are made from the data in public domain or data licensed under the free licenses, so you can use them for any purpose without of charge.

 

 


API Documentation: http://jvectormap.com/documentation/

Examples: http://jvectormap.com/examples/world-gdp/

Download: http://jvectormap.com/download/

Source: https://github.com/bjornd/jvectormap

 


 

 

Thanks,
SABIT SOLUTIONS

Advanced Sleek Date Range Picker plugin based on Bootstrap, jQuery and Moment.Js

Advanced Sleek Date Range Picker plugin based on Bootstrap, jQuery and Moment.Js

Date Range Picker

 

An advanced date range picker input based on bootstrap-daterangepicker plugin. The date range picker widget is styled for Bootstrap 3.x and creates a dropdown menu from which a user can select a range of dates. If the plugin is invoked with no options, it will present two calendars to choose a start and end date from. Optionally, you can provide a list of date ranges the user can select from of choosing dates from the calendars. If attached to a text input, the selected dates will be inserted into the text box. Otherwise, you can provide a custom callback function to receive the selection.

Additional enhancements added for this widget:

  • allows ability to work with Bootstrap input group addons and set the picker position to point at the input-group-addon icon.
  • enhanced translation features providing ability to add/configure your translation for each language. In order to create your own translation, please follow these steps.
  • automatically trigger change of base field to enforce Yii ActiveField validation
  • ability to set the widget to display a preset dropdown of date options within a container (and hidden input).
  • style the container options as per your need using templates
  • automatically disable date-range based on disabled/readonly options.

 

If invoked with no options, it will present two calendars to choose a start and end date from. Optionally, you can provide a list of date ranges the user can select from instead of choosing dates from the calendars. If attached to a text input, the selected dates will be inserted into the text box. Otherwise, you can provide a custom callback function to receive the selection.

The component can also be used as a single date picker by setting the `singleDatePicker` option to `true`.

DEMO: http://www.dangrossman.info/2012/08/20/a-date-range-picker-for-twitter-bootstrap/

Usage

This component relies on Bootstrap, Moment.js and jQuery.

Separate stylesheets are included for use with Bootstrap 2 or Bootstrap 3.

Basic usage:

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="moment.js"></script>
<script type="text/javascript" src="daterangepicker.js"></script>
<link rel="stylesheet" type="text/css" href="bootstrap.css" />
<link rel="stylesheet" type="text/css" href="daterangepicker-bs3.css" />

<script type="text/javascript">
$(document).ready(function() {
  $('input[name="daterange"]').daterangepicker();
});
</script>

The constructor also takes an optional options object and callback function. The function will be called whenever the selected date range has been changed by the user, and is passed the start and end dates (moment date objects) and the predefined range label chosen (if any), as parameters. It will not fire if the picker is closed without any change to the selected dates.

$('input[name="daterange"]').daterangepicker(
  { 
    format: 'YYYY-MM-DD',
    startDate: '2013-01-01',
    endDate: '2013-12-31'
  },
  function(start, end, label) {
    alert('A date range was chosen: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD'));
  }
);

Options

startDate: (Date object, moment object or string) The start of the initially selected date range

endDate: (Date object, moment object or string) The end of the initially selected date range

minDate: (Date object, moment object or string) The earliest date a user may select

maxDate: (Date object, moment object or string) The latest date a user may select

dateLimit: (object) The maximum span between the selected start and end dates. Can have any property you can add to a moment object (i.e. days, months)

timeZone: (string or number) The timezone that will be used to display the startDate and endDate in the calendar. This may be a string such as “-08:00” or an offset in minutes from Greenwich Mean Time. Uses Moment.js #zone, see the docs here for more information. If the timeZone option is not set, the calendar will use the time zone set on the startDate that has been passed in through the options, if it has one. Defaults to the local time zone

showDropdowns: (boolean) Show year and month select boxes above calendars to jump to a specific month and year

showWeekNumbers: (boolean) Show week numbers at the start of each week on the calendars

timePicker: (boolean) Allow selection of dates with times, not just dates

timePickerIncrement: (number) Increment of the minutes selection list for times (i.e. 30 to allow only selection of times ending in 0 or 30)

timePicker12Hour: (boolean) Use 12-hour instead of 24-hour times, adding an AM/PM select box

timePickerSeconds: (boolean) Show seconds in the timePicker

ranges: (object) Set predefined date ranges the user can select from. Each key is the label for the range, and its value an array with two dates representing the bounds of the range

opens: (string: ‘left’/’right’/’center’) Whether the picker appears aligned to the left, to the right, or centered under the HTML element it’s attached to

buttonClasses: (array) CSS class names that will be added to all buttons in the picker

applyClass: (string) CSS class string that will be added to the apply button

cancelClass: (string) CSS class string that will be added to the cancel button

format: (string) Date/time format string used by moment when parsing or displaying the selected dates

separator: (string) Separator string to display between the start and end date when populating a text input the picker is attached to

locale: (object) Allows you to provide localized strings for buttons and labels, and the first day of week for the calendars

singleDatePicker: (boolean) Show only a single calendar to choose one date, instead of a range picker with two calendars; the start and end dates provided to your callback will be the same single date chosen

parentEl: (string) jQuery selector of the parent element that the date range picker will be added to, if not provided this will be 'body'

Functions

Several functions are provided for updating the picker’s option and state after initialization:

setOptions(object, function): This function has the same signature and purpose as the date range picker’s constructor: it sets the picker’s options to their defaults, overrides them with any values in an options object you provide, and sets the callback for selection changes to whatever function you provide

setStartDate(Date/moment/string): Sets the date range picker’s currently selected start date to the provided date

setEndDate(Date/moment/string): Sets the date range picker’s currently selected end date to the provided date

Example usage:

//create a new date range picker
$('#daterange').daterangepicker({ startDate: '2014-03-05', endDate: '2014-03-06' });

//change the selected date range of that picker
$('#daterange').data('daterangepicker').setStartDate('2014-03-01');
$('#daterange').data('daterangepicker').setEndDate('2014-03-31');

Events

Several events are triggered on the element you attach the picker to, which you can listen for:

show.daterangepicker: Triggered when the picker is shown

hide.daterangepicker: Triggered when the picker is hidden

showCalendar.daterangepicker: Triggered when the calendar is shown

hideCalendar.daterangepicker: Triggered when the calendar is hidden

apply.daterangepicker: Triggered when the apply button is clicked

cancel.daterangepicker: Triggered when the cancel button is clicked

Some applications need a “clear” instead of a “cancel” functionality, which can be achieved by changing the button label and watching for the cancel event:

$('#daterange').daterangepicker({
  locale: { cancelLabel: 'Clear' }  
});

$('#daterange').on('cancel.daterangepicker', function(ev, picker) {
  //do something, like clearing an input
  $('#daterange').val('');
});

While passing in a callback to the constructor is the easiest way to listen for changes in the selected date range, you can also do something every time the apply button is clicked even if the selection hasn’t changed:

$('#daterange').daterangepicker();
$('#daterange').on('apply.daterangepicker', function(ev, picker) {
  console.log(picker.startDate.format('YYYY-MM-DD'));
  console.log(picker.endDate.format('YYYY-MM-DD'));
});

License

This code is made available under the same license as Bootstrap. Moment.js is included in this repository for convenience. It is available under the MIT license.



DEMO: http://www.dangrossman.info/2012/08/20/a-date-range-picker-for-twitter-bootstrap/
 

SOURCE: https://github.com/dangrossman/bootstrap-daterangepicker


 
Thanks,
SABIT SOLUTIONS

 

jQuery Knob – Nice, downward compatible, touchable, jQuery dial with interactions.

jQuery Knob – Nice, downward compatible, touchable, jQuery dial with interactions.

 

aterrien/jQuery-Knob · GitHub

  • canvas based ; no png or jpg sprites.
  • touch, mouse and mousewheel, keyboard events implemented.
  • downward compatible ; overloads an input element.

Example

<input type="text" value="75" class="dial">

<script>
    $(function() {
        $(".dial").knob();
    });
</script>

Options

Options are provided as attributes ‘data-option’:

<input type="text" class="dial" data-min="-50" data-max="50">

… or in the “knob()” call :

$(".dial").knob({
    'min':-50,
    'max':50
});

The following options are supported :

Behaviors :

  • min : min value | default=0.
  • max : max value | default=100.
  • step : step size | default=1.
  • angleOffset : starting angle in degrees | default=0.
  • angleArc : arc size in degrees | default=360.
  • stopper : stop at min & max on keydown/mousewheel | default=true.
  • readOnly : disable input and events | default=false.
  • rotation : direction of progression | default=clockwise.

UI :

  • cursor : display mode “cursor”, cursor size could be changed passing a numeric value to the option, default width is used when passing boolean value “true” | default=gauge.
  • thickness : gauge thickness.
  • lineCap : gauge stroke endings. | default=butt, round=rounded line endings
  • width : dial width.
  • displayInput : default=true | false=hide input.
  • displayPrevious : default=false | true=displays the previous value with transparency.
  • fgColor : foreground color.
  • inputColor : input value (number) color.
  • font : font family.
  • fontWeight : font weight.
  • bgColor : background color.

Hooks

<script>
    $(".dial").knob({
        'release' : function (v) { /*make something*/ }
    });
</script>
  • ‘release’ : executed on release

    Parameters :

    • value : int, current value
  • ‘change’ : executed at each change of the value

    Parameters :

    • value : int, current value
  • ‘draw’ : when drawing the canvas

    Context :

    • this.g : canvas context 2D (see Canvas documentation)
    • this.$ : jQuery wrapped element
    • this.o : options
    • this.i : input
    • … console.log(this);
  • ‘cancel’ : triggered on [esc] keydown
  • ‘format’ : allows to format output (add unit %, ms …)

The scope (this) of each hook function is the current Knob instance (refer to the demo code).

Example

<input type="text" value="75" class="dial">

<script>
    $(".dial").knob({
        'change' : function (v) { console.log(v); }
    });
</script>

Dynamically configure

<script>
    $('.dial').trigger(
        'configure',
        {
            "min":10,
            "max":40,
            "fgColor":"#FF0000",
            "skin":"tron",
            "cursor":true
        }
    );
</script>

Set the value

<script>
    $('.dial')
        .val(27)
        .trigger('change');
</script>

Supported browser

Tested on Chrome, Safari, Firefox, IE>=8.0 (IE8.0 with excanvas).

 


 

Website: http://anthonyterrien.com/knob/


 
Thanks,
SABIT SOLUTIONS

Easy Pie Charts – jQuery plugin to render pie charts using canvas elements with customization.

Easy Pie Charts – jQuery plugin to render pie charts using canvas elements with customization.


EASY PIE CHART by rendro

Easy pie chart is a jQuery plugin that uses the canvas element to render simple pie charts for single values. These charts are highly customizable, very easy to implement, scale to the resolution of the display of the client to provide sharp charts even on retina displays, and use requestAnimationFrame for smooth animations on modern devices.

 

EASY PIE CHART by rendro

Browser support

This plugin supports all major browsers that support the canvas element. With excanvas you can even render the charts on IE 7+8.

Get started

To use the easy pie chart plugin you need to load the current version of jQuery (testet with 1.7.2) and the source (css+js) of the plugin. You can also use bower to install the component:

bower install jquery.easy-pie-chart

Then just add the following lines to the head of your website:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="/path/to/jquery.easy-pie-chart.js"></script>

<link rel="stylesheet"type="text/css" href="/path/to/jquery.easy-pie-chart.css">

The second step is to add a element to your site to represent chart and add the data-percent attribute with the percent number the pie chart should have:

<div class="chart" data-percent="73">73%</div>

Finally you have to initialize the plugin with your desired configuration:

<script type="text/javascript">
$(function() {
    $('.chart').easyPieChart({
        //your configuration goes here
    });
});
</script>

Configuration parameter

You can pass a set of these options to the initialize function to set a custom behaviour and look for the plugin.

Property (Type) Default Description
barColor #ef1e25 The color of the curcular bar. You can pass either a css valid color string like rgb, rgba hex or string colors. But you can also pass a function that accepts the current percentage as a value to return a dynamically generated color.
trackColor #f2f2f2 The color of the track for the bar, false to disable rendering.
scaleColor #dfe0e0 The color of the scale lines, false to disable rendering.
lineCap round Defines how the ending of the bar line looks like. Possible values are: butt, round and square.
lineWidth 3 Width of the bar line in px.
size 110 Size of the pie chart in px. It will always be a square.
animate false Time in milliseconds for a eased animation of the bar growing, or false to deactivate.
onStart $.noop Callback function that is called at the start of any animation (only if animate is not false).
onStop $.noop Callback function that is called at the end of any animation (only if animate is not false).
onStep $.noop Callback function that is called during animations providing the current value (the context is the plugin, so you can access the DOM element via this.$el).

Plugin API

If you want to update the current percentage of the a pie chart, you can call the update method. The instance of the plugin is saved in the jQuery-data.

<script type="text/javascript">
$(function() {
    //create instance
    $('.chart').easyPieChart({
        animate: 2000
    });
    //update instance after 5 sec
    setTimeout(function() {
        $('.chart').data('easyPieChart').update(40);
    }, 5000);
});
</script>

Credits

Thanks to Rafal Bromirski for making this dribble shot which inspired me and Philip Thrasher for his CoffeeScript jQuery boilerplate

 

Thanks,
SABIT SOLUTIONS

jqPlot – Pure javascript / jQuery plotting and charting plugin. Versatile and Expandable!

jqPlot – Pure javascript / jQuery plotting and charting plugin.

leftcharts

A Versatile and Expandable jQuery Plotting Plugin!

jqPlot is a plotting and charting plugin for the jQuery Javascript framework. jqPlot produces beautiful line, bar and pie charts with many features:

  • Numerous chart style options.
  • Date axes with customizable formatting.
  • Up to 9 Y axes.
  • Rotated axis text.
  • Automatic trend line computation.
  • Tooltips and data point highlighting.
  • Sensible defaults for ease of use

jqPlot is an open source project dual licensed under the MIT and GPL version 2 licenses. You are free to choose the license that best suits your project
//

Computation and drawing of lines, axes, shadows even the grid itself is handled by pluggable “renderers”. Not only are the plot elements customizable, plugins can expand functionality of the plot too! There are plenty of hooks into the core jqPlot code allowing for custom event handlers, creation of new plot types, adding canvases to the plot, and more!

jqPlot Usage

Introduction

jqPlot is a jQuery plugin to generate pure client-side javascript charts in your web pages.

The jqPlot home page is at http://www.jqplot.com/.

The project page and downloads are at http://www.bitbucket.org/cleonello/jqplot/.

Below are a few examples to demonstrate jqPlot usage.  These plots are shown as static images.  Many more examples of dynamically rendered plots can be seen on the test and examples pages here: ../../tests/.

Include the Files

jqPlot requires jQuery (1.4.3+ required for certain features). jQuery is included in the distribution.  To use jqPlot include jquery, the jqPlot jQuery plugin, jqPlot css file and optionally the excanvas script for IE support in your web page.  Note, excanvas is required only for IE versions below 9.  IE 9 includes native support for the canvas element and does not require excanvas:

<!--[if lt IE 9]><script language="javascript" type="text/javascript" src="excanvas.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="jquery.jqplot.min.js"></script>
<link rel="stylesheet" type="text/css" href="jquery.jqplot.css" />

Add a plot container

Add a container (target) to your web page where you want your plot to show up.  Be sure to give your target a width and a height:

<div id="chartdiv" style="height:400px;width:300px; "></div>

Create a plot

Then, create the actual plot by calling the $.jqplot plugin with the id of your target and some data:

$.jqplot('chartdiv',  [[[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]]]);

Which will produce a chart like:

Plot Options

You can customize the plot by passing options to the $.jqplot function.  Options are described in jqPlot Options in the jqPlotOptions.txt file.  An example of options usage:

$.jqplot('chartdiv',  [[[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]]],
{ title:'Exponential Line',
  axes:{yaxis:{min:-10, max:240}},
  series:[{color:'#5FAB78'}]
});

Which will produce a plot like:

Using Plugins

You can use jqPlot plugins (that is, plugins to the jqPlot plugin) by including them in your html after you include the jqPlot plugin.  Here is how to include the log axis plugin:

<link rel="stylesheet" type="text/css" href="jquery.jqplot.css" />
<!--[if IE]><script language="javascript" type="text/javascript" src="excanvas.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="jquery.jqplot.min.js"></script>
<script language="javascript" type="text/javascript" src="jqplot.logAxisRenderer.js"></script>

Important note: For jqplot builds r529 and above (0.9.7r529 and higher), you must explicitly enable plugins via either the { show: true } plugin option to the plot or by using the $.jqplot.config.enablePlugins = true; config options set on the page before plot creation.  Only plugins that can be immediately active upon loading are affected.  This includes non-renderer plugins like cursor, dragable, highlighter, and trendline.

Here is a the same $.jqplot call but with a log y axis:

$.jqplot('chartdiv',  [[[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]]],
{ title:'Exponential Line',
  axes:{yaxis:{renderer: $.jqplot.LogAxisRenderer}},
  series:[{color:'#5FAB78'}]
});

Which produces a plot like:

You can further customize with options specific to the log axis plugin:

$.jqplot('chartdiv',  [[[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]]],
{ title:'Exponential Line',
  axes:{yaxis:{renderer: $.jqplot.LogAxisRenderer, tickDistribution:'power'}},
  series:[{color:'#5FAB78'}]
});

Which makes a plot like:

For a full list of options, see jqPlot Options in the jqPlotOptions.txt file.

You can add as many plugins as you wish.  Order is generally not important.  Some plugins, like the highlighter plugin which highlights data points near the mouse, don’t need any extra options or setup to function.  Highlighter does have additional options which the user can set.

Other plugins, the barRenderer for example, provide functionality the must be specified in the chart options object.  To render a series as a bar graph with the bar renderer, you would first include the plugin after jqPlot:

<script language="javascript" type="text/javascript" src="plugins/jqplot.barRenderer.min.js"></script>

Then you would create a chart like:

$.jqplot('chartdiv',  [[34.53, 56.32, 25.1, 18.6]], {series:[{renderer:$.jqplot.BarRenderer}]});

Here the default LineRenderer is replaced by a BarRenderer to generate a bar graph for the first (an only) series.


Download: https://bitbucket.org/cleonello/jqplot/downloads/


Thanks,
SABIT SOLUTIONS