我正在尝试使用canvasjs.js创建一个图表。
canvasjs.js内置提供缩放和摇摄通过拖动鼠标在条形上,但我需要做缩放和平移按钮单击。下面是我的代码,我尝试在单击DrawGraph按钮时创建一个图表。
<div id="chartContainer" style="height: 250px; width: 100%; margin: auto; border:1px solid black;">
</div>
<button type="button" id="zoom-in" onclick="DrawGraph()">
DrawGraph</button>
<button onclick="Reset()">Reset</button>
<input type="button" value="+" onClick="zoomIn()"/>
<input type="button" value="-" onClick="zoomOut()"/>
<script>
function DrawGraph() {
var arr=[];
for(i=0;i<100;i++)
{
if(i%2==0)
{
arr.push({x:i,y:10,color:"red"})
}
else
{
arr.push({x:i,y:10,color:"blue"})
}
}
var chart = new CanvasJS.Chart("chartContainer",
{
zoomEnabled: true,
width: 760, //Sets the Canvas Width
height: 150, // Sets the Canvas Height
theme: "theme3", // Sets the Theme (we have theme-1.theme-2,theme-3)- Default theme-1
// X axis Grid Thickness and Inteval that Points Should Represents (ex: 0-3000)
axisX: {
gridThickness: 0.0,
labelFontSize: 0.1, // x-axis label
tickLength: 0.0, // separation between the labels
lineThickness: 1, // x-axis Line thickness
minimum: 0,
},
// Y axis Grid Thickness and Inteval that Points Should Represents (ex: 0-3000)
axisY: {
gridThickness: 0.0,
interval: 10,
labelFontSize: 0.1,
tickLength: 0.0,
lineColor: "white", // Line Color Y-axis
lineThickness: 0.1
},
toolTip:{
enabled: false,
},
dataPointMaxWidth: 5, // Setting maximum width of columns
// X and Y value settings
data: [
{
type: "column",
click: onClick,
// mouseover: onMouseover,
dataPoints: arr
}]
});
// Canvas Js
chart.render();
// chart.Reset();
function onClick(e) {
alert(e.dataSeries.type + ", dataPoint { x:" + e.dataPoint.x + ", y: " + e.dataPoint.y + " }");
}
}
</script>下面是摇摆不定的东西:小提琴
任何帮助都是非常感谢的。提前谢谢。
发布于 2015-10-28 12:26:17
您可以在axises上设置viewportMaximum和viewportMinimum值,并在v1.8 (仍然是beta版)上呈现图表,但是对于当前版本,开发人员认为这是不可能的。
问:在API上还有缩放和pan的编程访问吗?因此,我们可以实现缩放按钮快速缩放,如1周,1个月,等等? 答:到目前为止,还没有访问这些数据的方法。但我正在考虑对未来版本的API访问。
下面是有关v1.8:http://canvasjs.com/blog/10/07/sync-multiple-chart-ranges-zoom-vertically的更多详细信息
也许你可以考虑使用另一个图表库。http://www.highcharts.com/stock/demo/basic-line
https://stackoverflow.com/questions/33389077
复制相似问题