theming.html 16.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
<!DOCTYPE html>

<html>
<head>
	
	<title>Chart Theming</title>

    <link class="include" rel="stylesheet" type="text/css" href="../jquery.jqplot.min.css" />
    <link rel="stylesheet" type="text/css" href="examples.min.css" />
    <link type="text/css" rel="stylesheet" href="syntaxhighlighter/styles/shCoreDefault.min.css" />
    <link type="text/css" rel="stylesheet" href="syntaxhighlighter/styles/shThemejqPlot.min.css" />
  
  <!--[if lt IE 9]><script language="javascript" type="text/javascript" src="../excanvas.js"></script><![endif]-->
    <script class="include" type="text/javascript" src="../jquery.min.js"></script>
    
   
</head>
<body>
    <div class="logo">
   <div class="nav">
   <a class="nav" href="../../../index.php"><span>&gt;</span>Home</a>
   <a class="nav"  href="../../../docs/"><span>&gt;</span>Docs</a>
   <a class="nav"  href="../../download/"><span>&gt;</span>Download</a>
   <a class="nav" href="../../../info.php"><span>&gt;</span>Info</a>
   <a class="nav"  href="../../../donate.php"><span>&gt;</span>Donate</a>
   </div>
</div>
    <div class="example-content">

    <div class="example-nav">
  <a href="smoothedLine.html">Previous</a> <a href="./">Examples</a> <a href="waterfall.html">Next</a></div>

      
<!-- Example scripts go here -->

<style type="text/css">
.jqplot-target {
    margin: 30px;
}
</style>

<p>jqPlot has basic theming support for commonly styled atributes of plot elements.  Upon creation, each plot will have a "themeEngine" that controls modificaition, adding, removing and activating of plot themes.  In addition, each plot will have a "Default" theme which corresponds to the styling of the plot at plot creation.<p>
    
<p>Creation of new themes is easy.  A "style" object is created with properties for the various plot elements to be styles.  Attached to each of those is an ojbect with the actual styling properties.  A simple style object might look like:</p>

<pre>
    gabe = {
        series: [
            {color: 'rgba(216, 159, 60, 0.4)'},
            {color: 'rgba(159, 216, 60, 0.4)'},
            {color: 'rgba(60, 159, 216, 0.4)'},
        ],
        grid: {
            backgroundColor: '#DEA493'
        }
    }
</pre>

<p>This new style would then be added to the plot's themeEngine as a new theme.  it can then be activated by calling the plot's <code>activateTheme</code> method.</p>
<pre>
    plot1b.themeEngine.newTheme('gabe', gabe);
    plot1b.activateTheme('gabe');
</pre>
    
<div id="chart1b" class="plot" style="width:400px;height:260px;"></div>
<p>Select Theme for area plot:
<select id="p1bswitcher" onchange="switch1b();">
    <option value="Default" selected>Default</option>
    <option value="gabe">gabe</option>
</select>
</p>

<p>Themes can be reused between plots.  Here a style object is created and assigned to two different plots.  For convenience, the theme is given the same name when added to each plot's themeEngine.  Since each plot keeps it's own copy of the theme, the names do not need to be the same.  Also note that themes are added as deep copies by value and not by reference.  This avoids strange behavior due to the cascading nature of css related styles.</p>

<pre>
    temp = {
        seriesStyles: {
            seriesColors: ['red', 'orange', 'yellow', 'green', 'blue', 'indigo'],
            highlightColors: ['lightpink', 'lightsalmon', 'lightyellow', 'lightgreen', 'lightblue', 'mediumslateblue']
        },
        legend: {
            fontSize: '8pt'
        },
        title: {
            fontSize: '18pt'
        },
        grid: {
            backgroundColor: 'rgb(211, 233, 195)'
        }
    };
    
    plot3.themeEngine.newTheme('uma', temp);
    plot5.themeEngine.newTheme('uma', temp);
</pre>

<p>Select Theme for funnel and pie charts at same time:
<select id="p35switcher" onchange="switch35();">
    <option value="Default" selected>Default</option>
    <option value="uma">uma</option>
</select>
</p>

<div id="chart3" class="plot" style="width:400px;height:320px;"></div>

<p>Select Theme for funnel plot:
<select id="p3switcher" onchange="switch3();">
    <option value="Default" selected>Default</option>
    <option value="uma">uma</option>
</select>
</p>

<div id="chart5" class="plot" style="width:400px;height:260px;"></div>

<p>Select Theme for pie chart:
<select id="p5switcher" onchange="switch5();">
    <option value="Default" selected>Default</option>
    <option value="uma">uma</option>
</select>
</p>

<p>There are various was to create and edit themes for a plot.  Below are two different methods for creating additional themes for a line plot and adding them to the plots themeEngine.  Here the <code>axesStyles</code> property is used to supply styling to all axes at one time.  A similar property, <code>seriesStyles</code>, exists for styling all series of a plot at one time. Note, neither of these methods is as straightforward as using the <code>newTheme()</code> method of the plots themeEngine, but are included for illustrative purposes.</p>

<pre> 
    e1 = plot1.themeEngine;
    brass = e1.copy('Default', 'brass');
    brass.title.fontFamily = 'Copperplate, Impact';
    brass.grid.backgroundColor = "rgb(216, 198, 114)";
    brass.grid.drawGridlines = false;
    brass.series[0].lineWidth = 6.5;
    brass.series[0].markerOptions.show = false;
    brass.axesStyles.label.fontFamily = "Copperplate, 'Copperplate Gothic Light', Impact";
    brass.axesStyles.ticks.fontFamily = "Copperplate, 'Copperplate Gothic Light', Impact";
    brass.axesStyles.label.fontSize = '14pt';
    
    temp = {
        grid: {
            backgroundColor: "#593D2B",
            gridLineColor: '#E8E8E8',
            gridLineWidth: 3
        },
        title: {
            fontFamily: '"Comic Sans MS", cursive',
            fontSize: '18pt',
            textColor: '#C7CC4E'
        },
        seriesStyles: {
            color: "#DBBCAF",
            lineWidth: 8,
            markerOptions: {
                show: false
            }
        },
        axes: {
            xaxis: {
                label: {
                    fontFamily: '"Comic Sans MS", cursive',
                    textColor: '#C7CC4E'
                }
            }
        }
    };
    
    chocolate = plot1.themeEngine.copy('Default', 'chocolate', temp);
</pre>

<div id="chart1" class="plot" style="width:400px;height:260px;"></div>

<p>Select theme for line chart:
<select id="p1switcher" onchange="switch1();">
    <option value="Default" selected>Default</option>
    <option value="brass">brass</option>
    <option value="chocolate">chocolate</option>
</select>
</p>

<p>The example below shows more extensive use of the various styling options to give the chart a rather ugly and dated appearence.  Note that, for bar (and funnel, pie and donut charts), <code>highlightColors</code> can be specified as an array of colors which will be applied to each bar individually, as a single string giving a color to apply to all bars, or as an empty array which will force jqPlot to auto calculate highlight colors based on the current bar color.<p>
    
<pre>
    oldstyle = {
        title: {
            fontFamily: 'Times New Roman',
            textColor: 'black'
        },
        axesStyles: {
           borderWidth: 0,
           ticks: {
               fontSize: '12pt',
               fontFamily: 'Times New Roman',
               textColor: 'black'
           },
           label: {
               fontFamily: 'Times New Roman',
               textColor: 'black'
           }
        },
        grid: {
            backgroundColor: 'white',
            borderWidth: 0,
            gridLineColor: 'black',
            gridLineWidth: 2,
            borderColor: 'black'
        },
        series: [
            {color: 'red', highlightColors: ['aqua', 'black', 'blue', 'fuchsia', 'gray', 'green', 'lime', 'maroon', 'navy', 'olive', 'purple', 'red', 'silver', 'teal', 'white', 'yellow']},
            {color: 'green', highlightColors: []},
            {color: 'blue', highlightColors: []},
            {color: 'yellow', highlightColors: 'rgb(255, 245, 185)'}
        ],
        legend: {
            background: 'white',
            textColor: 'black',
            fontFamily: 'Times New Roman',
            border: '1px solid black'
        }
    };
    
    plot2.themeEngine.newTheme('oldstyle', oldstyle);
</pre>

<div id="chart2" class="plot" style="width:760px;height:360px;"></div>

<p>Select theme for bar chart:
<select id="p2switcher" onchange="switch2();">
    <option value="Default" selected>Default</option>
    <option value="oldstyle">oldstyle</option>
</select>
</p>

  
  </div>
  

<script language="javascript" type="text/javascript">
$(document).ready(function(){

    l1 = [['Seoul', 1], ['Paris', 7], ['Singapore',3], ['Hong  Kong',5], ['Chicago', 2], ['New York', 9]];
    l2 = [11, 9, 5, 12, 14];
    l3 = [4, 8, 5, 3, 6];
    l4 = [12, 6, 13, 11, 2];
    l5 = [4, -3, 3, 6, 2, -2];

    pop1980 = [7071639, 2968528, 3005072, 1595138, 789704, 1688210, 785940, 904599];
    pop1990 = [7322564, 3485398, 2783726, 1630553, 983403, 1585577, 935933, 1006877];
    pop2000 = [8008654, 3694644, 2896051, 1974152, 1322025, 1517550, 1160005, 1188603];
    pop2008 = [8363710, 3833995, 2853114, 2242193, 1567924, 1447395, 1351305, 1279910];

    ticks = ["New York", "Los Angeles", "Chicago", "Houston", "Phoenix", "Philadelphia", "San Antonio", "Dallas"];

    plot1 = $.jqplot('chart1',[l2],{
       title: 'Line Chart',
       highlighter: {
           show:true
       },
       cursor: {
           show: true,
           zoom: true
       },
       axes: {
           xaxis: {
               label: 'Sample'
           }
       }
    });
    
    plot1b = $.jqplot('chart1b',[l2, l3, l4],{
       stackSeries: true,
       showMarker: false,
       seriesDefaults: {
           fill: true
       }
    });

    plot2 = $.jqplot('chart2',[pop1980, pop1990, pop2000, pop2008],{
       title: 'City Population',
       legend: {
           show: true
       },
       seriesDefaults: {
           renderer: $.jqplot.BarRenderer,
           rendererOptions: {
               barPadding: 2
           }
       },
       series: [
          {label: '1980'},
          {label: '1990'},
          {label: '2000'},
          {label: '2008 (est)'}
       ],
       axes: {
           xaxis: {
               label: 'City',
               renderer: $.jqplot.CategoryAxisRenderer,
               tickRenderer: $.jqplot.CanvasAxisTickRenderer,
               labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
               ticks: ticks,
               tickOptions: {
                   angle: -30
                }
           },
           yaxis: {
               tickRenderer: $.jqplot.CanvasAxisTickRenderer,
               max: 9000000,
               min: 0,
               tickOptions: {
                   formatString: '%d',
                   angle: -30
                }
           }
       }
    });
    
    plot3 = $.jqplot('chart3',[l1],{
       title: 'Global City Index',
       legend: {
           show: true,
           rendererOptions: {
               // numberColumns: 2,
               fontSize: '10pt'
           }
        },
       seriesDefaults: {
           renderer: $.jqplot.FunnelRenderer
       }
    });
        
    plot5 = $.jqplot('chart5',[l1],{
       title: 'Pie Chart',
       seriesDefaults: {
           renderer: $.jqplot.PieRenderer
       },
       legend: {
           show: true
       }
    });
        
    e1 = plot1.themeEngine;
    brass = e1.copy('Default', 'brass');
    brass.title.fontFamily = 'Copperplate, Impact';
    brass.grid.backgroundColor = "rgb(216, 198, 114)";
    brass.grid.drawGridlines = false;
    brass.series[0].lineWidth = 6.5;
    brass.series[0].markerOptions.show = false;
    // brass.axes.xaxis.ticks.fontFamily = "Copperplate, Impact";
    brass.axesStyles.label.fontFamily = "Copperplate, 'Copperplate Gothic Light', Impact";
    brass.axesStyles.ticks.fontFamily = "Copperplate, 'Copperplate Gothic Light', Impact";
    brass.axesStyles.label.fontSize = '14pt';
    
    temp = {
        grid: {
            backgroundColor: "#593D2B",
            gridLineColor: '#E8E8E8',
            gridLineWidth: 3
        },
        title: {
            fontFamily: '"Comic Sans MS", cursive',
            fontSize: '18pt',
            textColor: '#C7CC4E'
        },
        seriesStyles: {
            color: "#DBBCAF",
            lineWidth: 8,
            markerOptions: {
                show: false
            }
        },
        axes: {
            xaxis: {
                label: {
                    fontFamily: '"Comic Sans MS", cursive',
                    textColor: '#C7CC4E'
                }
            }
        }
    };
    
    chocolate = plot1.themeEngine.copy('Default', 'chocolate', temp);
    
    gabe = {
        series: [
            {color: 'rgba(216, 159, 60, 0.6)'},
            {color: 'rgba(159, 216, 60, 0.6)'},
            {color: 'rgba(60, 159, 216, 0.6)'},
        ],
        grid: {
            backgroundColor: '#DEA493'
        }
    }
    
    gabe = plot1b.themeEngine.newTheme('gabe', gabe);
    
    oldstyle = {
        title: {
            fontFamily: 'Times New Roman',
            textColor: 'black'
        },
        axesStyles: {
           borderWidth: 0,
           ticks: {
               fontSize: '12pt',
               fontFamily: 'Times New Roman',
               textColor: 'black'
           },
           label: {
               fontFamily: 'Times New Roman',
               textColor: 'black'
           }
        },
        grid: {
            backgroundColor: 'white',
            borderWidth: 0,
            gridLineColor: 'black',
            gridLineWidth: 2,
            borderColor: 'black'
        },
        series: [
            {color: 'red', highlightColors: ['aqua', 'black', 'blue', 'fuchsia', 'gray', 'green', 'lime', 'maroon', 'navy', 'olive', 'purple', 'red', 'silver', 'teal', 'white', 'yellow']},
            {color: 'green', highlightColors: []},
            {color: 'blue', highlightColors: []},
            {color: 'yellow', highlightColors: 'rgb(255, 245, 185)'}
        ],
        legend: {
            background: 'white',
            textColor: 'black',
            fontFamily: 'Times New Roman',
            border: '1px solid black'
        }
    };
    
    plot2.themeEngine.newTheme('oldstyle', oldstyle);
    
    temp = {
        seriesStyles: {
            seriesColors: ['red', 'orange', 'yellow', 'green', 'blue', 'indigo'],
            highlightColors: ['lightpink', 'lightsalmon', 'lightyellow', 'lightgreen', 'lightblue', 'mediumslateblue']
        },
        legend: {
            fontSize: '8pt'
        },
        title: {
            fontSize: '18pt'
        },
        grid: {
            backgroundColor: 'rgb(211, 233, 195)'
        }
    };
    
    plot3.themeEngine.newTheme('uma', temp);
    plot5.themeEngine.newTheme('uma', temp);
    
});

function switch1() {
    var th = $('#p1switcher').val();
    plot1.activateTheme(th);
}

function switch1b() {
    var th = $('#p1bswitcher').val();
    plot1b.activateTheme(th);
}

function switch2() {
    var th = $('#p2switcher').val();
    plot2.activateTheme(th);
}

function switch3() {
    var th = $('#p3switcher').val();
    plot3.activateTheme(th);
}

function switch5() {
    var th = $('#p5switcher').val();
    plot5.activateTheme(th);
}

function switch35() {
    var th = $('#p35switcher').val();
    plot3.activateTheme(th);
    plot5.activateTheme(th);
}


</script>

<!-- End example scripts -->

<!-- Don't touch this! -->


    <script class="include" type="text/javascript" src="../jquery.jqplot.min.js"></script>
    <script type="text/javascript" src="syntaxhighlighter/scripts/shCore.min.js"></script>
    <script type="text/javascript" src="syntaxhighlighter/scripts/shBrushJScript.min.js"></script>
    <script type="text/javascript" src="syntaxhighlighter/scripts/shBrushXml.min.js"></script>
<!-- End Don't touch this! -->

<!-- Additional plugins go here -->
  <script language="javascript" type="text/javascript" src="../plugins/jqplot.barRenderer.min.js"></script>
  <script language="javascript" type="text/javascript" src="../plugins/jqplot.categoryAxisRenderer.min.js"></script>
  <script language="javascript" type="text/javascript" src="../plugins/jqplot.pieRenderer.min.js"></script>
  <script language="javascript" type="text/javascript" src="../plugins/jqplot.donutRenderer.min.js"></script>
  <script language="javascript" type="text/javascript" src="../plugins/jqplot.highlighter.min.js"></script>
  <script language="javascript" type="text/javascript" src="../plugins/jqplot.cursor.min.js"></script>
  <script language="javascript" type="text/javascript" src="../plugins/jqplot.funnelRenderer.min.js"></script>
  <script language="javascript" type="text/javascript" src="../plugins/jqplot.canvasTextRenderer.min.js"></script>
  <script language="javascript" type="text/javascript" src="../plugins/jqplot.canvasAxisTickRenderer.min.js"></script>
  <script language="javascript" type="text/javascript" src="../plugins/jqplot.canvasAxisLabelRenderer.min.js"></script>

<!-- End additional plugins -->


	</div>	
	<script type="text/javascript" src="example.min.js"></script>

</body>


</html>