ChartJS 如何更改图表模板上坐标轴、标题和图例格式

wj8zmpe1  于 2022-11-06  发布在  Chart.js
关注(0)|答案(1)|浏览(262)

我还是一个新的javascript和html,我已经设法建立了一个简单的计算器,也将图形的一些输出。这样做,我使用下面的chartjs模板。我希望能够改变字体的y轴,标题,和图例,因为它看起来真的'波涛汹涌'时,创建,但是,我不知道我会找到/定义适当的参数,他们会是什么。此外,如果图表标题太长,我该如何将其换行?2我可以在脚本中指定这些项吗?3或者我必须操作dx.chartjs文件吗?4如果是这样,我需要在哪里进行更改?
非常感谢你的帮助

<html>
    <head>
    <title> Savings </title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">

        <script src="js/jquery-1.10.2.min.js"></script>
        <script src="js/knockout-3.0.0.js"></script>
        <script src="js/globalize.min.js"></script>
        <script src="js/dx.chartjs.js"></script>
    </head>

    <script language="javascript">

    function btnCalculateTotal_Click()
    {

    houses = 0;
    cars = 0;

    houses = Number(frmSimpleCalculator.txtValue1.value);
    cars = Number(frmSimpleCalculator.txtValue2.value);
    sngTotal = houses + cars
    frmSimpleCalculator.txtTotal.value = sngTotal;

    test = 200
    var dataSource = [{ savings: "", Houses: sngTotal, Cars: 300 },];

    $("#chartContainer").dxChart({
    dataSource: dataSource,
    commonSeriesSettings: {
        argumentField: "savings",
        type: "bar",
        hoverMode: "allArgumentPoints",
        selectionMode: "allArgumentPoints",
        label: {
            visible: true,
            format: "fixedPoint",
            precision: 0
                }
                          },
    series: [
        { valueField: "Houses", name: "Houses" },
        { valueField: "Cars", name: "Cars" }
            ],

    title: "Savings potential",
    legend: {
        verticalAlignment: "bottom",
        horizontalAlignment: "center"
            },

    pointClick: function (point) {
        this.select();
                                 }
                            });
    }

    </script>

    <body bgcolor="#aaaaaa">

    <table style="background-color:black; color:white; width:800">
    <tr>
    <td>
    <strong>calculator</strong>
    </td>
    </tr>
    </table>

    <form name="frmSimpleCalculator" action="" method="get">
    <fieldset name="fraSimpleCalculator" style="width:1">
    <legend>Economic Savings Calculator</legend>
    <table width="300" border="0">

    <!-- Value 1 -->
    <tr>
    <td align="left">
    Houses:
    </td>
    <td align="right">
    <input type="text" value="50000" name="txtValue1" size="10" maxlength="10" style="text-align:right">
    </td>
    </tr>

    <!-- Value 2 -->
    <tr>
    <td align="left">
    Cars:
    </td>
    <td align="right">
    <input type="text" value="25" name="txtValue2" size="10" maxlength="10" style="text-align:right">
    </td>
    </tr>

    <!-- Horizontal rule -->
    <tr>
    <td align="center" colspan="2">
    <hr />
    </td>
    </tr>

    <!-- Total -->
    <tr>
    <td align="left">
    Total:
    </td>
    <td align="right">
    <input type="text" value="0" name="txtTotal" size="10" maxlength="5" style="text-align:right">
    </td>
    </tr>

    <!-- Calculate Button -->
    <tr>
    <td align="center" colspan="2">
    <input type="button" value="Calculate Total" name="btnCalculateTotal" style="width:150" OnClick="btnCalculateTotal_Click();">
    </td>
    </tr>

    <!-- Calculate Chart Button -->
    <tr>
    <td align="center" colspan="2">
    <input type="button" value="Update Chart" name="btnCalculateChart" style="width:150" OnClick="Thomas();">
    </td>
    </tr>

        <div class="content">
            <div class="pane">
                <div class="long-title"><h3></h3></div>
                <div id="chartContainer" style="width: 250px; height: 440px;" style="position:absolute; TOP:200px; LEFT:350px"></div>       
            </div>
        </div>
    </body>
    </html>
u7up0aaq

u7up0aaq1#

1)您可以通过相应options元素“font”属性设置标题、图例和轴的字体选项

legend: {
   font: {
      color: 'black',
      family: 'Zapf-Chancery, cursive',
      opacity: 1,
      weight: 700
    }
}

您可以在ChartJS documentation中找到更多示例。
2)您可以使用HTML标记br将标题换行到第二行

title: "This is my<br/>long title"

相关问题