GithubHelp home page GithubHelp logo

tawen / china.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from francis-shuoch/china.js

0.0 1.0 0.0 824 KB

China.js is a little javascript lib that helps you create a choropleth map of China with one line of code, with boundaries of Chinese provinces.

HTML 85.52% CSS 14.48%

china.js's Introduction

#China.js#

China.js is a little javascript lib that helps you create a choropleth map of China with one line of code, with boundaries of Chinese provinces.

what is a choropleth map ? see this example:

china-provinces-gdp-per-capital

It is using the svg data from wikipedia. It will create a svg element on the page.

Dependencies

Usage

<link href="/path/to/china.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/path/to/china.js"></script>
  • china is attached to windows. You can create a svg map of china simplify by invoking
<svg id="china"></svg>
<script type="text/javascript"></script>
  var ch = china();
  ch.draw("#china");
</script>

You can pass in options to control the behavior of the choropleth by province. Like,

ch.draw("#china", {
	hlj: { color: black }
});

This will display the Heilongjiang(黑龙江) province in black. For a list of province id (like hlj), see the section provinces below.

API

china.js uses the same chaining style as d3.js, which means you can get back the china object itself after you call functions on it. By doing so, it is more convenient for you to set the properties of the choropleth map of China by evoking chained functions, like width, height or colors. For example, ch.width(800).height(600).draw("#china");

draw(selector, [options]): selector is a css selector so you can attach the svg. It must be a svg element on the page. options can be used to control the behavior of each province, for example,

ch.draw("#china", {
	hlj: { color: black }
});

This will display the Heilongjiang(黑龙江) province in black. For a list of province id you can use (like hlj), see the section provinces below.

width: set the width of the svg map. By default it is 970 (px).

for example:

ch.width(800).draw("#china");

height: set the height of the svg map. By default it is 700 (px).

scale: set the scale attribute of the svg map. By default 1, which means the default size (970x700).

colorDefault: set the default background color of provinces.

colorLake: set the default background color of water area.

language: set the language to use of the name of the provinces. By default it is simplified chinese. For example

ch.language("en").draw("#china");  # use English name.

Currently we only support Simplified Chinese ("cn"), Traditional Chinese ("tw") and English ("en").

tooltipHtml: a function, that return a tooltip html element to display the information about a province. It accepts one argument which is the javascript object representing a province along with the options you passed in draw() method. By default it will display the province name.

provinces

provinces-name

for each icon, the last line is the id used to distinguish each province. For example, to change the background color of Heilongjiang(黑龙江) province to black, use

ch.draw("#china", {
	hlj: { color: black }
});

Showcase

china.js's People

Contributors

francis-shuoch avatar

Watchers

tawen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.